docker / build-push-action

GitHub Action to build and push Docker images with Buildx
https://github.com/marketplace/actions/build-and-push-docker-images
Apache License 2.0
4.24k stars 541 forks source link

Image gets built even if the build args have empty input #926

Closed ashishjullia closed 1 year ago

ashishjullia commented 1 year ago

Troubleshooting

Before submitting a bug report please read the Troubleshooting doc.

Behaviour

Steps to reproduce this issue

  1. Use the yaml provided below
  2. Target any repo
  3. Run the actions step

Also, here is the Dockerfile

# Specify the base image
FROM node:16-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
ARG MYSQL_HOST 
ENV MYSQL_HOST=$MYSQL_HOST
RUN chmod +x entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"]

Expected behaviour

If there is the empty value for ${{ env.MYSQL_HOST }} then the build step should not proceed, means if should check the value being empty or not

Actual behaviour

The image is being built even if the value is empty for ${{ env.MYSQL_HOST }}

Configuration

# paste your YAML workflow file here and remove sensitive data
      - name: Build, tag, and push image to Amazon ECR
        id: build-image
        uses: docker/build-push-action@v4
        with:
          context: .
          push: true
          tags: testrepo/${{ github.sha }}
          cache-from: type=gha
          cache-to: type=gha,mode=max
          build-args: |
            "MYSQL_HOST=${{ env.MYSQL_HOST }}"

Logs

I'm not sure whether such checks can be directly performed using this action or a separate step will be required just to check whether the values being passed are empty of not.

ashishjullia commented 1 year ago

I've a few more ARGs and when I'm changing there values it is getting updated in the image but not for this one.

I even passed the hardcoded value for "MYSQL_HOST=hello" and at the same time I updated the value for other ARGs, the other ones are getting updated but not this^ one.

ashishjullia commented 1 year ago

There was some issue with my setup, I was able to fix that but still, if an empty value is passed can that be cached as an error?

crazy-max commented 1 year ago

if an empty value is passed can that be cached as an error?

Not sure why you would like to pass MYSQL_HOST in your Dockerfile during build. This is a runtime env from what I see and should be handled in your entrypoint script. But anyway you can do that validation in your Dockerfile like:

ARG MYSQL_HOST 
RUN if [ -z "$MYSQL_HOST" ] ; then echo "The MYSQL_HOST argument is missing!" ; exit 1; fi
ENV MYSQL_HOST=$MYSQL_HOST
RUN chmod +x entrypoint.sh