1+ name : Push Docker image
2+ on :
3+ push :
4+ branches :
5+ - master
6+ tags :
7+ - .*
8+ jobs :
9+ push_docker_image :
10+ name : Push Docker image to GitHub Packages
11+ runs-on : ubuntu-22.04
12+ steps :
13+ - name : Check out the repo
14+ uses : actions/checkout@v4
15+ - name : Determine tag name
16+ run : |
17+ VERSION=$(echo $GITHUB_REF | sed -e 's,.*/\(.*\),\1,')
18+
19+ # If we're not tagged in git, tag as latest.
20+ if [[ "$GITHUB_REF" != "refs/tags/"* ]]; then
21+ VERSION=latest
22+ fi
23+
24+ # Preserve our tag name for later
25+ echo "tag_name=${VERSION,,}" >> $GITHUB_ENV
26+ # Use lowercase name of repository, as buildx rejects the name otherwise.
27+ echo "repository=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
28+ - name : Set up Docker Buildx
29+ uses : docker/setup-buildx-action@v1
30+ - name : Cache Docker layers
31+ uses : actions/cache@v4
32+ with :
33+ path : /tmp/.buildx-cache
34+ key : ${{ runner.os }}-buildx-${{ github.sha }}
35+ restore-keys : |
36+ ${{ runner.os }}-buildx-
37+ - name : Login to GitHub Container Registry
38+ uses : docker/login-action@v1
39+ with :
40+ registry : ghcr.io
41+ username : ${{ github.actor }}
42+ password : ${{ secrets.GITHUB_TOKEN }}
43+ - name : Build and push
44+ id : docker_build
45+ uses : docker/build-push-action@v2
46+ with :
47+ push : true
48+ tags : ghcr.io/${{ env.repository }}:${{ env.tag_name }}
49+ cache-from : type=local,src=/tmp/.buildx-cache
50+ cache-to : type=local,dest=/tmp/.buildx-cache
0 commit comments