-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache docker when using Github actions #2196
Changes from 5 commits
ab1da75
8fcbbb3
f4beade
efc701d
081224c
0dd227c
5f87605
b25b3d9
1f6ac2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ on: | |
- master | ||
- 'release/**' | ||
|
||
env: | ||
DOCKER_USER: ${{secrets.DOCKERHUB_USERID}} | ||
DOCKER_TOKEN: ${{secrets.DOCKERHUB_TOKEN}} | ||
|
||
jobs: | ||
cancel: | ||
|
@@ -17,37 +20,107 @@ jobs: | |
uses: styfle/[email protected] | ||
with: | ||
access_token: ${{ github.token }} | ||
|
||
check_image: | ||
name: Check if image exists in registry | ||
runs-on: ubuntu-latest | ||
outputs: | ||
imageexists: ${{ steps.check_image.outputs.imageexists }} | ||
imagetag: ${{ steps.image_hash.outputs.imagetag }} | ||
imageexists_sles: ${{ steps.check_image.outputs.imageexists_sles }} | ||
imagetag_sles: ${{ steps.image_hash.outputs.imagetag_sles }} | ||
|
||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Create Image Tag | ||
id: image_hash | ||
run: | | ||
echo "imagetag=rocm/migraphx-private:hip-clang-${{hashFiles('**/hip-clang.docker', '**/*requirements.txt', '**/install_prereqs.sh', '**/rbuild.ini')}}" >> $GITHUB_OUTPUT | ||
echo "imagetag_sles=rocm/migraphx-private:hip-clang-sles-${{hashFiles('**/tools/docker/sles.docker', '**/*requirements.txt', '**/install_prereqs.sh', '**/rbuild.ini')}}" >> $GITHUB_OUTPUT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should use a different image name such as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed, I created another repo rocm/migraphx-sles-private |
||
|
||
- name: Check if image is built already | ||
id: check_image | ||
env: | ||
DOCKERIMAGE: ${{ steps.image_hash.outputs.imagetag }} | ||
DOCKERIMAGE_SLES: ${{ steps.image_hash.outputs.imagetag_sles }} | ||
run: | | ||
echo $DOCKER_TOKEN | docker login -u $DOCKER_USER --password-stdin | ||
|
||
if [[ "$(docker manifest inspect $DOCKERIMAGE 2> /dev/null)" != "" ]]; then | ||
causten marked this conversation as resolved.
Show resolved
Hide resolved
|
||
echo "imageexists=true" >> $GITHUB_OUTPUT | ||
echo "Image already exists, skip building available" | ||
else | ||
echo "imageexists=false" >> $GITHUB_OUTPUT | ||
echo "Tag does not exist, build and publishing required" | ||
fi | ||
|
||
if [[ "$(docker manifest inspect $DOCKERIMAGE_SLES 2> /dev/null)" != "" ]]; then | ||
echo "imageexists_sles=true" >> $GITHUB_OUTPUT | ||
echo "SLES Image already exists, skip building available" | ||
else | ||
echo "imageexists_sles=false" >> $GITHUB_OUTPUT | ||
echo "SLES Tag does not exist, build and publishing required" | ||
fi | ||
|
||
|
||
build_image: | ||
name: Build image | ||
runs-on: ROCM-Ubuntu | ||
umangyadav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
needs: check_image | ||
if: ${{ needs.check_image.outputs.imageexists != 'true' }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Build and publish | ||
env: | ||
DOCKERIMAGE: ${{ needs.check_image.outputs.imagetag }} | ||
run: | | ||
echo $DOCKER_TOKEN | docker login -u $DOCKER_USER --password-stdin | ||
docker build . --file hip-clang.docker --tag $DOCKERIMAGE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a code change to do that. I'd like to first get this in "as is" and than can create a PR that doubles down on the caching. |
||
docker push $DOCKERIMAGE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should also push There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup will do exactly that in next PR |
||
|
||
build_SLES_image: | ||
name: Build SLES image | ||
runs-on: ROCM-Ubuntu | ||
needs: check_image | ||
if: ${{ needs.check_image.outputs.imageexists_sles != 'true' }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Build and publish SLES | ||
env: | ||
DOCKERIMAGE: ${{ needs.check_image.outputs.imagetag_sles }} | ||
run: | | ||
echo $DOCKER_TOKEN | docker login -u $DOCKER_USER --password-stdin | ||
docker build . --file tools/docker/sles.docker --tag $DOCKERIMAGE; | ||
umangyadav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
docker push $DOCKERIMAGE; | ||
|
||
|
||
tidy: | ||
runs-on: ROCM-Ubuntu | ||
needs: [ build_image, check_image ] | ||
env: | ||
DOCKERIMAGE: ${{ needs.check_image.outputs.imagetag }} | ||
|
||
if: ${{ !cancelled() && (needs.build_image.result == 'success' || needs.build_image.result == 'skipped') }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
# In this step, this action saves a list of existing images, | ||
# the cache is created without them in the post run. | ||
# It also restores the cache if it exists. | ||
- name: Docker layer cache | ||
uses: jpribyl/[email protected] | ||
with: | ||
key: docker-layer-caching-migraphx-${{hashFiles('hip-clang.docker', '**/*requirements.txt', '**/install_prereqs.sh', 'rbuild.ini')}} | ||
restore-keys: | ||
docker-layer-caching-migraphx- | ||
# Ignore the failure of a step and avoid terminating the job. | ||
continue-on-error: true | ||
|
||
- name: Restore cache files for tidy | ||
uses: actions/cache/restore@v3 | ||
id: tidy_restore | ||
with: | ||
path: tidy-cache | ||
key: tidy-cache-${{ github.ref }} | ||
restore-keys: tidy-cache- | ||
- name: Build the Docker image | ||
|
||
- name: Docker Login | ||
run: | | ||
docker build . --file hip-clang.docker --tag migraphx | ||
echo $DOCKER_TOKEN | docker login -u $DOCKER_USER --password-stdin | ||
|
||
- name: Clang tidy | ||
shell: bash -c "docker run -i -v=$GITHUB_WORKSPACE:/data -w /data migraphx bash < {0}" | ||
- name: Clang Tidy | ||
shell: bash -c "docker run -i -v=$GITHUB_WORKSPACE:/data -w /data $DOCKERIMAGE bash < {0}" | ||
run: | | ||
mkdir build | ||
cd build | ||
|
@@ -84,21 +157,14 @@ jobs: | |
|
||
cppcheck: | ||
runs-on: ROCM-Ubuntu | ||
needs: [ build_image, check_image ] | ||
env: | ||
DOCKERIMAGE: ${{ needs.check_image.outputs.imagetag }} | ||
|
||
if: ${{ !cancelled() && (needs.build_image.result == 'success' || needs.build_image.result == 'skipped') }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
# In this step, this action saves a list of existing images, | ||
# the cache is created without them in the post run. | ||
# It also restores the cache if it exists. | ||
- name: Docker layer cache | ||
uses: jpribyl/[email protected] | ||
with: | ||
key: docker-layer-caching-migraphx-${{hashFiles('hip-clang.docker', '**/*requirements.txt', '**/install_prereqs.sh', 'rbuild.ini')}} | ||
restore-keys: | ||
docker-layer-caching-migraphx- | ||
# Ignore the failure of a step and avoid terminating the job. | ||
continue-on-error: true | ||
|
||
- name: Restore cache files for cppcheck | ||
id: cppcheck_restore | ||
uses: actions/cache/restore@v3 | ||
|
@@ -107,11 +173,13 @@ jobs: | |
key: cppcheck-cache-${{ hashFiles('cppcheck.rules', 'CMakeLists.txt') }}-${{ github.ref }} | ||
restore-keys: cppcheck-cache-${{ hashFiles('cppcheck.rules', 'CMakeLists.txt') }}- | ||
|
||
- name: Build the Docker image | ||
run: docker build . --file hip-clang.docker --tag migraphx | ||
- name: Docker Login | ||
run: | | ||
echo $DOCKER_TOKEN | docker login -u $DOCKER_USER --password-stdin | ||
|
||
|
||
- name: Cppcheck | ||
shell: bash -c "docker run -i -v=$GITHUB_WORKSPACE:/data -w /data migraphx bash < {0}" | ||
shell: bash -c "docker run -i -v=$GITHUB_WORKSPACE:/data -w /data $DOCKERIMAGE bash < {0}" | ||
run: | | ||
mkdir build | ||
cd build | ||
|
@@ -142,56 +210,39 @@ jobs: | |
|
||
|
||
format: | ||
runs-on: ROCM-Ubuntu | ||
runs-on: ubuntu-latest | ||
needs: [ build_image, check_image ] | ||
env: | ||
DOCKERIMAGE: ${{ needs.check_image.outputs.imagetag }} | ||
|
||
if: ${{ !cancelled() && (needs.build_image.result == 'success' || needs.build_image.result == 'skipped') }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
# In this step, this action saves a list of existing images, | ||
# the cache is created without them in the post run. | ||
# It also restores the cache if it exists. | ||
- name: Docker layer cache | ||
uses: jpribyl/[email protected] | ||
with: | ||
key: docker-layer-caching-migraphx-${{hashFiles('hip-clang.docker', '**/*requirements.txt', '**/install_prereqs.sh', 'rbuild.ini')}} | ||
restore-keys: | ||
docker-layer-caching-migraphx- | ||
# Ignore the failure of a step and avoid terminating the job. | ||
continue-on-error: true | ||
- name: Docker Login | ||
run: | | ||
echo $DOCKER_TOKEN | docker login -u $DOCKER_USER --password-stdin | ||
|
||
- name: Build the Docker image | ||
run: docker build . --file hip-clang.docker --tag migraphx | ||
|
||
- name: Check formatting | ||
shell: bash -c "docker run -i -v=$GITHUB_WORKSPACE:/data -w /data migraphx bash < {0}" | ||
shell: bash -c "docker run -i -v=$GITHUB_WORKSPACE:/data -w /data $DOCKERIMAGE bash < {0}" | ||
run: | | ||
set -e | ||
git config --global --add safe.directory /data | ||
python3 tools/format.py origin/${{ github.event_name == 'pull_request' && github.base_ref || 'develop' }} | ||
|
||
sles: | ||
runs-on: ROCM-Ubuntu | ||
needs: [ build_SLES_image, check_image ] | ||
env: | ||
DOCKERIMAGE: ${{ needs.check_image.outputs.imagetag_sles }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
# In this step, this action saves a list of existing images, | ||
# the cache is created without them in the post run. | ||
# It also restores the cache if it exists. | ||
- name: Docker layer cache | ||
uses: jpribyl/[email protected] | ||
with: | ||
key: docker-layer-caching-migraphx-sles-${{hashFiles('hip-clang.docker', '**/*requirements.txt', '**/install_prereqs.sh', 'rbuild.ini')}} | ||
restore-keys: | ||
docker-layer-caching-migraphx-sles- | ||
# Ignore the failure of a step and avoid terminating the job. | ||
continue-on-error: true | ||
|
||
- name: Build the Docker image | ||
run: docker build . --file tools/docker/sles.docker --tag migraphx-sles | ||
|
||
- name: Restore cache files for ccache | ||
uses: actions/cache/restore@v3 | ||
id: ccache_restore | ||
|
@@ -200,8 +251,12 @@ jobs: | |
key: ccache-sles-${{ github.ref }} | ||
restore-keys: ccache-sles- | ||
|
||
- name: Docker Login | ||
run: | | ||
echo $DOCKER_TOKEN | docker login -u $DOCKER_USER --password-stdin | ||
|
||
- name: Build migraphx | ||
shell: bash -c "docker run -i -v=$GITHUB_WORKSPACE:/data -w /data migraphx-sles bash < {0}" | ||
shell: bash -c "docker run -i -v=$GITHUB_WORKSPACE:/data -w /data $DOCKERIMAGE bash < {0}" | ||
umangyadav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
run: | | ||
set -e | ||
export CCACHE_COMPRESSLEVEL=10 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should have one variable for image name and then another for the tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do that as part of the --cache-from update in another PR