skip to Main Content

EDIT

I want to pass the last git short hash into my React app build with the following command:
git log -1 --pretty=%h

Thus in my Dockerfile I want something such as:

ARG REACT_APP_GIT_SHORTHASH
RUN git clone https://[email protected]/paulywill/repo.git && cd repo && export REACT_APP_GIT_SHORTHASH=`git log -1 --pretty=%h`
ENV REACT_APP_GIT_SHORTHASH $REACT_APP_GIT_SHORTHASH

In my Github Actions build I’m getting the following:

Step 6/14 : ARG REACT_APP_GIT_SHORTHASH
 ---> Running in f45f530d5c76
Removing intermediate container f45f530d5c76
 ---> 87a91c010aaf
Step 7/14 : RUN git clone https://***@github.com/paulywill/repo.git && cd repo && export REACT_APP_GIT_SHORTHASH=$(git log -1 --pretty=%h)
 ---> Running in b8a8fa3cd703
Cloning into 'repo'...
Removing intermediate container b8a8fa3cd703
 ---> 5bbf3a76b928
Step 8/14 : ENV REACT_APP_GIT_SHORTHASH $REACT_APP_GIT_SHORTHASH
 ---> Running in f624f2e59dc6
Removing intermediate container f624f2e59dc6
 ---> d15c3c276062

Are these command even visible or able to pass values if they’re different intermediate containers?

2

Answers


  1. Chosen as BEST ANSWER

    As per a previous answer and thanks in part for @david-maze for pointing me in the right direction, I can easily grab the git short hash before the docker build.

    .github/deploy.yml

    ...
     - name: Set outputs
          id: vars
          run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
        - name: Check outputs
          run: echo ${{ steps.vars.outputs.sha_short }}
       ...
         docker build --build-arg REACT_APP_GIT_SHORTHASH=${{ steps.vars.outputs.sha_short }} -t $ECR_REPOSITORY_CLIENT .
    

    Dockerfile

    FROM node:16-alpine
    ARG VERSION
    ENV VERSION $VERSION
    ARG REACT_APP_GIT_SHORTHASH
    ENV REACT_APP_GIT_SHORTHASH $REACT_APP_GIT_SHORTHASH
    ...
    

  2. ROM ubuntu:20.04
    ARG REACT_APP_GIT_SHORTHASH
    RUN apt-get update -y
    RUN apt-get install git -y
    RUN git clone https://github.com/pooya-mohammadi/deep_utils.git
    WORKDIR deep_utils
    RUN REACT_APP_GIT_SHORTHASH=`git log -1 --pretty=%h`
    ENV REACT_APP_GIT_SHORTHASH $REACT_APP_GIT_SHORTHASH
    

    Change deep_utils with your repo name. I found the cd <directory> to be problematic.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search