-
Notifications
You must be signed in to change notification settings - Fork 2
142 lines (136 loc) · 5.14 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Build and Push Docker Image
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
platform: [linux/amd64, linux/arm64]
steps:
- name: Checkout
uses: actions/checkout@v4
- 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.platform }} | cut -d'/' -f2)" >> $GITHUB_ENV
- name: Add SSH key
if: matrix.platform == 'linux/arm64'
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
mkdir -p ~/.ssh
ssh-keyscan -p ${{ secrets.ARM_NODE_PORT }} -H ${{ secrets.ARM_NODE_ADDR }} >> ~/.ssh/known_hosts
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
echo "${{ secrets.SSH_PRIVATE_KEY }}" | ssh-add -
- name: Set up Docker Buildx for amd64
if: matrix.platform == 'linux/amd64'
uses: docker/setup-buildx-action@v3
with:
platforms: ${{ matrix.platform }}
- name: Set up Docker Buildx for arm64
if: matrix.platform == 'linux/arm64'
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
uses: docker/setup-buildx-action@v3
with:
platforms: ${{ matrix.platform }}
endpoint: ssh://${{ secrets.ARM_NODE_USER }}@${{ secrets.ARM_NODE_ADDR }}:${{ secrets.ARM_NODE_PORT }}
- name: Build and export
id: buildx
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
uses: docker/build-push-action@v5
with:
context: .
provenance: false
platforms: ${{ matrix.platform }}
cache-from: type=gha
cache-to: type=gha,mode=max
# image to tar
outputs: type=tar,dest=./${{ env.OS }}-image.tar
- name: Image ID Output for amd64
if: matrix.platform == 'linux/amd64'
run: echo "${{ steps.buildx.outputs.imageid }}" > "${{ env.OS }}-image-id.txt"
- name: Upload image id
uses: actions/upload-artifact@v4
with:
name: ${{ env.OS }}-image-id.txt
path: ${{ env.OS }}-image-id.txt
- name: Upload image tar
uses: actions/upload-artifact@v4
with:
name: ${{ env.OS }}-image.tar
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 (amd64)
uses: actions/download-artifact@v4
with:
name: amd64-image-id.txt
- name: Download image id (arm64)
uses: actions/download-artifact@v4
with:
name: arm64-image-id.txt
- name: Download image tar (amd64)
uses: actions/download-artifact@v4
with:
name: amd64-image.tar
- name: Download image tar (arm64)
uses: actions/download-artifact@v4
with:
name: arm64-image.tar
- name: Set image id output
id: imageid
run: |
echo "AMD64_ID=$(cat amd64-image-id.txt)" >> $GITHUB_ENV
echo "ARM64_ID=$(cat arm64-image-id.txt)" >> $GITHUB_ENV
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v2
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@v3
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@v3
- name: Load image
run: docker import amd64-image.tar
- name: Load image
run: docker import arm64-image.tar
- name: Tag
run: |
docker manifest create \
${{ secrets.ARTIFACT_REGISTRY }}/libnare/${{ github.event.repository.name }}/${{ github.ref_name }}:latest \
${{ env.AMD64_ID }} \
${{ env.ARM64_ID }}
docker manifest annotate --arch amd64 \
${{ secrets.ARTIFACT_REGISTRY }}/libnare/${{ github.event.repository.name }}/${{ github.ref_name }}:latest \
${{ env.AMD64_ID }}
docker manifest annotate --arch arm64 \
${{ secrets.ARTIFACT_REGISTRY }}/libnare/${{ github.event.repository.name }}/${{ github.ref_name }}:latest \
${{ env.ARM64_ID }}
- name: Push
run: docker manifest push ${{ secrets.ARTIFACT_REGISTRY }}/libnare/${{ github.event.repository.name }}/${{ github.ref_name }}:latest
- name: Summary
run: |
echo "Job completed! 🎉" >> $GITHUB_STEP_SUMMARY
echo "Image pushed to `${{ secrets.ARTIFACT_REGISTRY }}/libnare/${{ github.event.repository.name }}/${{ github.ref_name }}:latest`" >> $GITHUB_STEP_SUMMARY
echo "## Details" >> $GITHUB_STEP_SUMMARY
echo "linux/arm64: `${{ env.ARM64_ID }}`" >> $GITHUB_STEP_SUMMARY
echo "linux/amd64: `${{ env.AMD64_ID }}`" >> $GITHUB_STEP_SUMMARY