How to pass artifact build from gitlab ci to dockerfile?

Viewed 3905

I need a way to pass a job artifact from gitlab ci to a Dockerfile, so I can copy it into a directory. What is the path where this artifact is located?

Thank you!

3 Answers

Steps:

  1. use artifacts at your stage.
  2. use dependencies to pass dependencies to the current stage.
  3. And you can see files in Dockerfile.

For example, I run the vueJS project, the main flow:

  1. stage1: build. Run npm run build:prod in vueJS project
build-dist:
  stage: build-dist
  image: node
  script:
    - npm run build:prod
  artifacts:
    paths:
      - dist/
  1. stage2: use dependencies
build-docker:
  stage: build-docker
  image: docker:stable
  script:
    - docker build
  dependencies:
    - build-dist
  1. stage3: copy dist to Dockerfile
FROM fholzer/nginx-brotli

COPY ./dist /usr/share/nginx/html

COPY ./nginx.conf /etc/nginx/nginx.conf

You can use RUN --mount=type=secret
Build images with BuildKit

There is an example to show how to copy credentials into dockerfile This dockerfile

# syntax = docker/dockerfile:experimental
RUN --mount=type=secret,id=aws,target=/root/.aws/credentials \
        cat /root/.aws/credentials

This the CI

$ docker build -t test --secret id=aws,src=$HOME/.aws/credentials .
Related