-
-
Notifications
You must be signed in to change notification settings - Fork 54
68 lines (60 loc) · 2.33 KB
/
docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: Publish Docker Image
on:
push:
branches:
- 'main'
jobs:
build-and-push-docker-image:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image for ARM64
uses: docker/build-push-action@v5
with:
platforms: linux/arm64
push: true
file: docker/Dockerfile.arm64
tags: |
discuit/discuit:${{ github.sha }}-arm64
- name: Build and push Docker image for AMD64
uses: docker/build-push-action@v5
with:
platforms: linux/amd64
push: true
file: docker/Dockerfile.amd64
tags: |
discuit/discuit:${{ github.sha }}-amd64
- name: Create and push Docker manifest
uses: int128/docker-manifest-create-action@v2
with:
tags: |
discuit/discuit:latest
discuit/discuit:${{ github.sha }}
sources: |
discuit/discuit:${{ github.sha }}-arm64
discuit/discuit:${{ github.sha }}-amd64
- name: Authenticate and obtain Docker Hub JWT token (for cleanup)
id: get_token
run: |
TOKEN=$(curl -s -H "Content-Type: application/json" \
-X POST -d '{"username": "${{ secrets.DOCKERHUB_USERNAME }}", "password": "${{ secrets.DOCKERHUB_TOKEN }}"}' \
https://hub.docker.com/v2/users/login/ | jq -r .token)
echo "::add-mask::$TOKEN" # Mask the token in the logs
echo "TOKEN=$TOKEN" >> $GITHUB_ENV
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Clean up old images
env:
TOKEN: ${{ env.TOKEN }}
run: |
curl -s -H "Authorization: JWT $TOKEN" -X DELETE "https://hub.docker.com/v2/repositories/discuit/discuit/tags/${{ github.sha }}-arm64/"
curl -s -H "Authorization: JWT $TOKEN" -X DELETE "https://hub.docker.com/v2/repositories/discuit/discuit/tags/${{ github.sha }}-amd64/"