-
Notifications
You must be signed in to change notification settings - Fork 0
136 lines (120 loc) · 5.35 KB
/
docker_build_push.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: build_and_push
on:
push:
branches:
- main
env:
GHCR_IMAGE_NAME: ${{ github.repository }}
DOCKERHUB_IMAGE_NAME: ${{ env.DOCKERHUB_REPOSITORY }}
jobs:
docker_build:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
attestations: write
id-token: write
strategy:
matrix:
architecture: [linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7]
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Log in to the Container registry
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@a64d0487d7069df33b279515d35d60fa80e2ea62
with:
images: |
docker.io/${{ env.DOCKERHUB_IMAGE_NAME }}
ghcr.io/${{ env.GHCR_IMAGE_NAME }}
tags: |
type=sha
labels: |
org.opencontainers.image.title=${{ env.GHCR_IMAGE_NAME }}
org.opencontainers.image.description = "tg2 IRIG-B or WWV timecode generator"
org.opencontainers.image.vendor="${{ env.GITHUB_REPOSITORY_OWNER }}"
org.opencontainers.image.url = "https://github.com/${{ github.repository }}"
org.opencontainers.image.source = "https://github.com/${{ github.repository }}"
org.opencontainers.image.version = "0.0.1"
org.opencontainers.image.created = "${{ github.event.head_commit.timestamp }}"
org.opencontainers.image.revision = "${{ github.sha }}"
org.opencontainers.image.licenses = "MIT"
annotations: |
org.opencontainers.image.title=${{ env.GHCR_IMAGE_NAME }}
org.opencontainers.image.description = "tg2 IRIG-B or WWV timecode generator"
org.opencontainers.image.vendor="${{ env.GITHUB_REPOSITORY_OWNER }}"
org.opencontainers.image.url = "https://github.com/${{ github.repository }}"
org.opencontainers.image.source = "https://github.com/${{ github.repository }}"
org.opencontainers.image.version = "0.0.1"
org.opencontainers.image.created = "${{ github.event.head_commit.timestamp }}"
org.opencontainers.image.revision = "${{ github.sha }}"
org.opencontainers.image.licenses = "MIT"
- name: Build Docker image
id: build
uses: docker/build-push-action@e050dfa622d93dfcc095192a984db567cb14f0f0
with:
context: .
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ matrix.architecture }}
outputs: type=registry
create_multi_platform_manifest_and_push:
runs-on: ubuntu-latest
needs: docker_build
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Log in to the Container registry
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push multi-platform manifest
id: push
run: |
docker buildx imagetools create \
--tag docker.io/${{ env.DOCKERHUB_IMAGE_NAME }}:${{ github.sha }} \
docker.io/${{ env.DOCKERHUB_IMAGE_NAME }}:${{ github.sha }}-linux/arm/v6 \
docker.io/${{ env.DOCKERHUB_IMAGE_NAME }}:${{ github.sha }}-linux/amd64 \
docker.io/${{ env.DOCKERHUB_IMAGE_NAME }}:${{ github.sha }}-linux/arm64 \
docker.io/${{ env.DOCKERHUB_IMAGE_NAME }}:${{ github.sha }}-linux/arm/v7
docker buildx imagetools create \
--tag ghcr.io/${{ env.GHCR_IMAGE_NAME }}:${{ github.sha }} \
ghcr.io/${{ env.GHCR_IMAGE_NAME }}:${{ github.sha }}-linux/arm/v6 \
ghcr.io/${{ env.GHCR_IMAGE_NAME }}:${{ github.sha }}-linux/amd64 \
ghcr.io/${{ env.GHCR_IMAGE_NAME }}:${{ github.sha }}-linux/arm64 \
ghcr.io/${{ env.GHCR_IMAGE_NAME }}:${{ github.sha }}-linux/arm/v7
- name: Generate artifact attestation (ghcr)
id: push-ghcr
uses: actions/attest-build-provenance@v1
with:
subject-name: ghcr.io/${{ env.GHCR_IMAGE_NAME }}
subject-digest: ${{ needs.docker_build_and_push.outputs.digest }}
push-to-registry: true
- name: Generate artifact attestation (dockerhub)
id: push-dockerhub
uses: actions/attest-build-provenance@v1
with:
subject-name: index.docker.io/${{ env.DOCKERHUB_IMAGE_NAME }}
subject-digest: ${{ needs.docker_build_and_push.outputs.digest }}
push-to-registry: true