G
G
goodw842021-02-10 15:32:31
Continuous Integration
goodw84, 2021-02-10 15:32:31

How to build a frontend based on a docker image?

  1. I use CI & CD in GitLab: I create a docker image with Composer and NPM, I do composer install and npm install inside
  2. I upload the image to the nexus repository and reference it in the next stage (frontend build)
  3. Getting the problem: npm WARN Local package.json exists, but node_modules missing, did you mean to install?


Source data:
.gitlab-ci.yml
stages:
  - dockerize
  - update-modules
  - build

dockerize:
    <<: *common
    <<: *shared
    stage: dockerize
    script:
        - docker build --build-arg DOCKER_REGISTRY -t ${DOCKER_REGISTRY}/${APP_NAME}:${VERSION} . -f ./docker/php-fpm/Dockerfile
        - docker push ${DOCKER_REGISTRY}/${APP_NAME}:${VERSION}
    when: manual

build-frontend:
  <<: *rules-default
  <<: *common
  <<: *docker
  image: ${DOCKER_REGISTRY}/${APP_NAME}:${VERSION}
  stage: build
  script: npm run prod


Dockerfile:
ARG DOCKER_REGISTRY
FROM $DOCKER_REGISTRY/php:7.4.7-fpm
USER root

RUN apt -y update
RUN apt -y --no-install-recommends install unzip wget curl libaio1 openssl

WORKDIR /app

RUN curl -sS https://getcomposer.org/installer -o composer-setup.php \
    && php composer-setup.php --install-dir=/usr/local/bin --filename=composer
RUN composer install --no-dev && rm ./composer-setup.php

RUN npm install [email protected] -g

Questions:
  1. How to make npm see node_modules at build stage? Where to take them from?
  2. How to deploy: run a docker image or can you unload the build from it and transfer it to a specialized deployment tool?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question