I'm having issues with my Github action where I'm trying to build my Docker image after building my jar and it throws this error:
Step 8/9 : COPY /home/runner/work/js-sites-client-api/js-sites-client-api/build/libs/client-portal-api.jar app.jar
COPY failed: file not found in build context or excluded by .dockerignore: stat home/runner/work/js-sites-client-api/js-sites-client-api/build/libs/client-portal-api.jar: file does not exist
Which doesn't make sense to me because I ran LS/PWD and I can see that the file IS there:
ls build/libs
cd build/libs
pwd
cd ../../
docker build . --file Dockerfile --tag ***/js-client-api:latest
shell: /usr/bin/bash -e {0}
env:
JAVA_HOME: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/11.0.14-1/x64
GRADLE_BUILD_ACTION_CACHE_RESTORED: true
-------------OUTPUT of ls/pwd------------
client-portal-api.jar
/home/runner/work/js-sites-client-api/js-sites-client-api/build/libs
Below is my github action:
...
jobs:
build:
...
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Change wrapper permissions
run: chmod x ./gradlew
- name: Build with Gradle
uses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7
with:
arguments: build
- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build the Docker image
run: |
ls build/libs
cd build/libs
pwd
cd ../../
docker build . --file Dockerfile --tag ${{ secrets.DOCKER_USERNAME }}/js-client-api:latest --build-arg WORKDIR=${{ github.workspace }}
- name: Push the Docker image
run: docker push ${{ secrets.DOCKER_USERNAME }}/js-client-api:latest
Any help would be much appreciated!
CodePudding user response:
This line in your Dockerfile is the issue:
COPY /home/runner/work/js-sites-client-api/js-sites-client-api/build/libs/client-portal-api.jar app.jar
. In a Dockerfile COPY
, the first argument is the location of the file(s) on the machine, which has to be a relative path, not an absolute one. Read more here
Multiple resources may be specified but the paths of files and directories will be interpreted as relative to the source of the context of the build.