fix: checking dockerhub credential beforehand in cache docker images … #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Cache Docker Images CI | ||
Check failure on line 1 in .github/workflows/cache-docker-images.yml GitHub Actions / .github/workflows/cache-docker-images.ymlInvalid workflow file
|
||
on: | ||
workflow_call: | ||
secrets: | ||
DOCKERHUB_USERNAME: | ||
required: false | ||
DOCKERHUB_TOKEN: | ||
required: false | ||
jobs: | ||
check-dockerhub-secrets-present: | ||
runs-on: [self-hosted, ubuntu-20.04, X64, small] | ||
env: | ||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | ||
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | ||
name: Check if DockerHub secrets are present | ||
outputs: | ||
secrets_present: ${{ env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != '' }} | ||
changes: | ||
needs: [ check-dockerhub-secrets-present ] | ||
if: ${{ always() && needs.check-dockerhub-secrets-present.outputs.secrets_present == 'true' }} | ||
runs-on: [self-hosted, ubuntu-20.04, X64, small] | ||
name: Filter commit changes | ||
outputs: | ||
cache_images: ${{ steps.filter.outputs.cache_images }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Filter commit changes | ||
uses: dorny/paths-filter@v2 | ||
id: filter | ||
with: | ||
base: ${{ github.ref }} | ||
list-files: "json" | ||
filters: | | ||
cache_images: | ||
- 'docker/compose.yml' | ||
- 'docker/compose-local-dev.overrides.yml' | ||
- 'docker/compose-local-dev-traces-v2.overrides.yml' | ||
pull-and-cache-images: | ||
needs: [ check-dockerhub-secrets-present, changes ] | ||
if: ${{ always() && needs.check-dockerhub-secrets-present.outputs.secrets_present == 'true' && needs.changes.outputs.cache_images == 'true' }} | ||
runs-on: [self-hosted, ubuntu-20.04, X64, small] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- name: Pull docker images from compose | ||
continue-on-error: true | ||
run: | | ||
docker compose -f docker/compose.yml -f docker/compose-local-dev-traces-v2.overrides.yml --profile l1 --profile l2 pull | ||
- name: Save Docker images | ||
run: | | ||
mkdir -p ~/docker-images | ||
images=$(docker compose -f docker/compose.yml -f docker/compose-local-dev-traces-v2.overrides.yml --profile l1 --profile l2 config | grep "image:" | awk '{print $2}') | ||
for image in $images; do | ||
imageFileName=$(echo $image | sed -e 's|.*/||' -e 's|:|-|' -e 's/\./_/g') | ||
echo $image - ${imageFileName} | ||
docker save $image > ~/docker-images/${imageFileName}.tar | ||
done | ||
- name: Cache common docker images | ||
continue-on-error: true | ||
uses: actions/cache/[email protected] | ||
with: | ||
path: ~/docker-images | ||
key: cached-images |