I am trying to use GitHub Actions to build a Docker image and publish it to Docker Hub.
I'm getting an error during the Build and push step when it is attempting to build the Docker image because it cannot find the target directory.
The Docker build step is looking in /tmp/buildkit-mount147850474/target but my JAR is in /home/runner/work/myrepo/myrepo/target/app-0.0.1-SNAPSHOT.jar.
How do I tell the Docker build step to use the correct directory?
I looked at working-directory but the documentation says it is only for run steps.
Error
#6 [3/3] COPY target/*.jar app.jar
#6 ERROR: lstat /tmp/buildkit-mount147850474/target: no such file or directory
Log snippet when it saves the JAR
[INFO] Building jar: /home/runner/work/myrepo/myrepo/target/app-0.0.1-SNAPSHOT.jar
Dockerfile
FROM openjdk:17-alpine
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
publish.yml
name: Publish Docker Image
on:
push:
tags:
- '*'
jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Set output
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
working-directory: ${{ github.workspace }}
with:
push: true
tags: ${{ github.repository }}:${{ steps.vars.outputs.tag }}
CodePudding user response:
I have a similar pipeline but when I use docker/build-push-action:
- I have no working-directory param
- I have a context param set to current directory in with map
Could you try to modify your Build and push step like this ?
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ github.repository }}:${{ steps.vars.outputs.tag }}
You can have a look at this example (https://morioh.com/p/2d04d286363b) and also at documentation of this action (https://github.com/docker/build-push-action)
