-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (124 loc) · 4.75 KB
/
build_and_publish.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
143
144
name: Build and Push Docker Image
on:
push:
branches:
- main
tags:
- '*'
workflow_dispatch:
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: image=moby/buildkit:latest
- name: Install docker-squash
run: |
pip install docker-squash
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Clone repo to build
run: git clone https://github.com/${{ github.repository }}.git repo
- name: Build and push image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ github.ref_name }}-huge
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Setup jq
uses: dcarbone/install-jq-action@v3
with:
version: "1.7"
force: true
- name: Squash the image
run: |
docker pull ghcr.io/${{ github.repository }}:${{ github.ref_name }}-huge && \
docker pull debian:bookworm && \
FROM_LAYER=$(docker inspect --format='{{json .RootFS.Layers}}' debian:bookworm | jq -r '.[-1]') && \
echo "FROM_LAYER: $FROM_LAYER" && \
docker-squash \
--from $FROM_LAYER \
--tag ghcr.io/${{ github.repository }}:${{ github.ref_name }} \
ghcr.io/${{ github.repository }}:${{ github.ref_name }}-huge
- name: Push squashed image
run: |
docker push ghcr.io/${{ github.repository }}:${{ github.ref_name }} && \
docker tag ghcr.io/${{ github.repository }}:${{ github.ref_name }} ${{ github.repository }}:${{ github.ref_name }} && \
docker push ${{ github.repository }}:${{ github.ref_name }}
- name: Push latest image
run: |
docker tag ghcr.io/${{ github.repository }}:${{ github.ref_name }} ghcr.io/${{ github.repository }}:latest && \
docker push ghcr.io/${{ github.repository }}:latest && \
docker tag ghcr.io/${{ github.repository }}:${{ github.ref_name }} ${{ github.repository }}:latest && \
docker push ${{ github.repository }}:latest
if: startsWith(github.ref, 'refs/tags/')
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: ${{ github.repository }}
short-description: ${{ github.event.repository.description }}
enable-url-completion: true
create-release:
runs-on: ubuntu-latest
needs: build-and-push
permissions: write-all
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Update CHANGELOG
id: changelog
uses: requarks/changelog-action@v1
with:
token: ${{ github.token }}
tag: ${{ github.ref_name }}
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: v${{ github.ref_name }}
body: |
Container images for this release:
- Docker Hub: `${{ github.repository }}:${{ github.ref_name }}`
- GitHub Container Registry: `ghcr.io/${{ github.repository }}:${{ github.ref_name }}`
${{ steps.changelog.outputs.changes }}
draft: false
prerelease: false
- name: Commit CHANGELOG.md
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: main
commit_message: 'docs: update CHANGELOG.md for ${{ github.ref_name }} [skip ci]'
file_pattern: CHANGELOG.md
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: ${{ github.repository }}
short-description: ${{ github.event.repository.description }}
enable-url-completion: true