We use gitlab ci across our build and deploy pipeline. When serving an static site or single page application, we use multiple build stages in gitlab. We define a builder container that builds the project from source code first, and then the artifacts are copied to the second stage where the continer is built for deployment.
FROM node:10 as builder ADD package.json /usr/src/app/ WORKDIR /usr/src/app RUN yarn install COPY . . RUN yarn build FROM nginx:stable COPY --from=builder /usr/src/app/build/ /var/www/html COPY nginx.conf /etc/nginx/nginx.conf EXPOSE 80 ENTRYPOINT ["nginx","-g","daemon off;"]
build_image: image: docker:git services: - docker:dind before_script: - apk update && apk add curl && apk add python script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker build -t $CI_REGISTRY_IMAGE:latest . - docker push $CI_REGISTRY_IMAGE:latest only: - master