Is it possible to get the git branch name in the docker file?

Not sure if this is possible. But I want to change this line of code inside the dockerfile

RUN $(npm bin)/ng build --prod --env=prod

to

RUN $(npm bin)/ng build --prod --env=test

Or better, how to do something like this in the gitbal-ci.yml file:

# Production build
build:
  stage: build
  script:
    - docker build --pull -t $CONTAINER_ENV_IMAGE .
    - docker push $CONTAINER_ENV_IMAGE
  args:
    - env=prod
  only:
    - master

# Test build
build:
  stage: build
  script:
    - docker build --pull -t $CONTAINER_ENV_IMAGE .
    - docker push $CONTAINER_ENV_IMAGE
  args:
    - env=test
  except:
    - master

but only if the git branch name is a test. I use gitlab to create images.

I need this to change the url api environment variable in angular. Is this possible or are there any better ways?

+4
source share
2 answers

Dockerfile . , , , , . , build args, docker build-build-arg =. , git_branch, env.

FROM busybox
ARG git_branch
RUN echo "Building $git_branch"
+2

docker 1.9 build prod dev build:

docker build --build-arg local_config=test

:

RUN $(npm bin)/ng build --prod --env=$local_config
+2

Source: https://habr.com/ru/post/1694540/


All Articles