Bernardo Guerreiro
Bernardo Guerreiro

Reputation: 51

How to pass artifact build from gitlab ci to dockerfile?

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!

Upvotes: 5

Views: 8437

Answers (3)

rovast
rovast

Reputation: 141

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

Upvotes: 6

fei yang
fei yang

Reputation: 83

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 .

Upvotes: 0

Stefan van Gastel
Stefan van Gastel

Reputation: 4478

You should use dependencies, the docs also state that job artifacts are passed to the next job by default.

The artifacts from the previous jobs will be downloaded and extracted in the context of the build.

Upvotes: 0

Related Questions