-
Notifications
You must be signed in to change notification settings - Fork 2
116 lines (110 loc) · 3.9 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
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
name: Build and Push Docker Image
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04, macos-14]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get commit sha
run: echo "COMMIT_SHA=$(git rev-parse --short=7 HEAD)" >> $GITHUB_ENV
- name: Get os name
run: echo "OS=$(echo ${{ matrix.os }} | cut -d'-' -f1)" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and Push
id: buildx
uses: docker/build-push-action@v4
with:
context: .
push: true
provenance: false
cache-from: type=gha
cache-to: type=gha,mode=max
# image to tar
outputs: type=local,dest=./${{ matrix.os }}-image.tar
- name: Image ID Output
run: echo "${{ steps.buildx.outputs.imageid }}" > "${{ env.OS }}-image.id"
- name: Upload image id
uses: actions/upload-artifact@v4
with:
name: ${{ env.OS }}-image-id
path: ${{ env.OS }}-image.id
- name: Upload image tar
uses: actions/upload-artifact@v4
with:
name: ${{ env.OS }}-image
path: ${{ env.OS }}-image.tar
tag-merge:
permissions:
contents: read
id-token: write
runs-on: ubuntu-22.04
needs: build
steps:
- name: Download image id
uses: actions/download-artifact@v4
with:
name: ubuntu-image-id
path: ubuntu-image.id
- name: Download image id
uses: actions/download-artifact@v4
with:
name: macos-image-id
path: macos-image.id
- name: Download image tar
uses: actions/download-artifact@v4
with:
name: ubuntu-image
path: ubuntu-image.tar
- name: Download image tar
uses: actions/download-artifact@v4
with:
name: macos-image
path: macos-image.tar
- name: Set image id output
id: imageid
run: |
echo "ubuntu-image=$(cat ubuntu-image.id)" >> $GITHUB_OUTPUT
echo "macos-image=$(cat macos-image.id)" >> $GITHUB_OUTPUT
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v1
with:
token_format: access_token
workload_identity_provider: ${{ secrets.IDENTITY_PROVIDER }}
service_account: ${{ secrets.SERVICE_ACCOUNT }}
- name: Login to Artifact Registry
uses: docker/login-action@v2
with:
registry: ${{ secrets.ARTIFACT_REGISTRY }}
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Load image
run: docker import ubuntu-image.tar
- name: Load image
run: docker import macos-image.tar
- name: Tag
run: |
docker manifest create \
${{ secrets.ARTIFACT_REGISTRY }}/libnare/${{ github.event.repository.name }}/${{ github.ref_name }}:${{ github.sha }} \
${{ steps.imageid.outputs.ubuntu-image }} \
${{ steps.imageid.outputs.macos-image }}
docker manifest annotate --arch amd64 \
${{ secrets.ARTIFACT_REGISTRY }}/libnare/${{ github.event.repository.name }}/${{ github.ref_name }}:${{ github.sha }} \
${{ steps.imageid.outputs.ubuntu-image }}
docker manifest annotate --arch arm64 \
${{ secrets.ARTIFACT_REGISTRY }}/libnare/${{ github.event.repository.name }}/${{ github.ref_name }}:${{ github.sha }} \
${{ steps.imageid.outputs.macos-image }}
- name: Push
run: docker manifest push ${{ secrets.ARTIFACT_REGISTRY }}/libnare/${{ github.event.repository.name }}/${{ github.ref_name }}:${{ github.sha }}