@@ -36,63 +36,106 @@ jobs:
3636 needs : check_changelog
3737
3838 env :
39- TEST_TAG : ghcr.io/${{ secrets.DOCKER_HUB_USERNAME }}/ discord-bot:test
39+ BASE_TAG : retroarcher/ discord-bot
4040
4141 steps :
4242 - name : Checkout
4343 uses : actions/checkout@v3
4444
45+ - name : Prepare
46+ id : prepare
47+ env :
48+ NEXT_VERSION : ${{ needs.check_changelog.outputs.next_version }}
49+ run : |
50+ # determine to push image to dockerhub and ghcr or not
51+ if [[ $GITHUB_EVENT_NAME == "push" ]]; then
52+ PUSH=true
53+ else
54+ PUSH=false
55+ fi
56+
57+ # setup the tags
58+ TAGS="${BASE_TAG}:${GITHUB_SHA},ghcr.io/${BASE_TAG}:${GITHUB_SHA}"
59+
60+ if [[ $GITHUB_REF == refs/heads/master ]]; then
61+ TAGS="${TAGS},${BASE_TAG}:latest,ghcr.io/${BASE_TAG}:latest"
62+ TAGS="${TAGS},${BASE_TAG}:master,ghcr.io/${BASE_TAG}:master"
63+ elif [[ $GITHUB_REF == refs/heads/nightly ]]; then
64+ TAGS="${TAGS},${BASE_TAG}:nightly,ghcr.io/${BASE_TAG}:nightly"
65+ else
66+ TAGS="${TAGS},${BASE_TAG}:test,ghcr.io/${BASE_TAG}:test"
67+ fi
68+
69+ if [[ ${NEXT_VERSION} != "" ]]; then
70+ TAGS="${TAGS},${BASE_TAG}:${NEXT_VERSION},ghcr.io/${BASE_TAG}:${NEXT_VERSION}"
71+ fi
72+
73+ echo ::set-output name=branch::${GITHUB_REF#refs/heads/}
74+ echo ::set-output name=build_date::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
75+ echo ::set-output name=commit::${GITHUB_SHA}
76+ echo ::set-output name=platforms::linux/386,linux/amd64,linux/arm64/v8
77+ echo ::set-output name=push::${PUSH}
78+ echo ::set-output name=tags::${TAGS}
79+
80+ - name : Set Up QEMU
81+ uses : docker/setup-qemu-action@v1
82+
4583 - name : Set up Docker Buildx
4684 uses : docker/setup-buildx-action@v1
85+ id : buildx
86+
87+ - name : Cache Docker Layers
88+ uses : actions/cache@v3
89+ with :
90+ path : /tmp/.buildx-cache
91+ key : ${{ runner.os }}-buildx-${{ github.sha }}
92+ restore-keys : |
93+ ${{ runner.os }}-buildx-
4794
4895 - name : Log in to Docker Hub
96+ if : ${{ steps.prepare.outputs.push == 'true' }} # PRs do not have access to secrets
4997 uses : docker/login-action@v1
5098 with :
5199 username : ${{ secrets.DOCKER_HUB_USERNAME }}
52100 password : ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
53101
54102 - name : Log in to the Container registry
103+ if : ${{ steps.prepare.outputs.push == 'true' }} # PRs do not have access to secrets
55104 uses : docker/login-action@v1
56105 with :
57106 registry : ghcr.io
58107 username : ${{ github.actor }}
59108 password : ${{ secrets.GITHUB_TOKEN }}
60109
61- - name : Build and export to Docker
110+ - name : Build and push
62111 uses : docker/build-push-action@v2
63112 with :
64113 context : ./
65114 file : ./Dockerfile
66- load : true
67- tags : ${{ env.TEST_TAG }}
115+ push : ${{ steps.prepare.outputs.push }}
116+ platforms : ${{ steps.prepare.outputs.platforms }}
117+ build-args : |
118+ BRANCH=${{ steps.prepare.outputs.branch }}
119+ COMMIT=${{ steps.prepare.outputs.commit }}
120+ BUILD_DATE=${{ steps.prepare.outputs.build_date }}
121+ tags : ${{ steps.prepare.outputs.tags }}
122+ cache-from : type=local,src=/tmp/.buildx-cache
123+ cache-to : type=local,dest=/tmp/.buildx-cache
68124
69- - name : Test Image
70- run : |
71- docker run -d -e 'bot_token=${{ secrets.DISCORD_TEST_BOT_TOKEN }}' ${{ env.TEST_TAG }}
72-
73- - name : Build and push (non master)
74- if : ${{ github.event_name == 'push' && github.ref != 'refs/heads/master' }}
75- uses : docker/build-push-action@v2
76- with :
77- context : ./
78- file : ./Dockerfile
79- push : true
80- tags : |
81- ${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:${{ github.ref_name }}
82- ghcr.io/${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:${{ github.ref_name }}
83-
84- - name : Build and push (master)
125+ - name : Update Docker Hub Description
85126 if : ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
86- uses : docker/build-push-action@v2
127+ uses : peter-evans/dockerhub-description@v3
87128 with :
88- context : ./
89- file : ./Dockerfile
90- push : true
91- tags : |
92- ${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:latest
93- ghcr.io/${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:latest
94- ${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:${{ needs.check_changelog.outputs.next_version }}
95- ghcr.io/${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:${{ needs.check_changelog.outputs.next_version }}
129+ username : ${{ secrets.DOCKER_HUB_USERNAME }}
130+ password : ${{ secrets.DOCKER_HUB_PASSWORD }} # token is not currently supported
131+ repository : ${{ env.BASE_TAG }}
132+ short-description : ${{ github.event.repository.description }}
133+ readme-filepath : ./DOCKER_README.md
134+
135+ create_release :
136+ runs-on : ubuntu-latest
137+ needs : [check_changelog, docker]
138+ steps :
96139
97140 - name : Create/Update GitHub Release
98141 if : ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
0 commit comments