-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (71 loc) · 2.95 KB
/
Copy pathdocker-publish.yml
File metadata and controls
82 lines (71 loc) · 2.95 KB
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
name: Publish Docker image to GHCR
# Builds the image on GitHub's runners and pushes it to ghcr.io.
#
# This exists because pushing from a laptop needs a Personal Access Token with
# `write:packages`. Actions gets an automatic GITHUB_TOKEN that already has it —
# see `permissions:` below — so nobody has to create or store a PAT.
on:
push:
tags: ["v*"] # every release tag publishes a matching image
workflow_dispatch: # ...and you can run it by hand from the Actions tab
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # this is what replaces the PAT
steps:
# The image is ~11GB. A stock runner has ~14GB free on /, which is not
# enough, so reclaim the preinstalled toolchains we don't use first.
- name: Free up disk space
run: |
echo "before:"; df -h / | tail -1
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/share/boost /usr/local/lib/node_modules \
/opt/hostedtoolcache/CodeQL "$AGENT_TOOLSDIRECTORY" || true
sudo apt-get clean
docker image prune -af || true
echo "after:"; df -h / | tail -1
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# linux/amd64 only: this image installs nine projects, and emulating
# arm64 under QEMU pushes the build past the runner's time limit.
platforms: linux/amd64
provenance: false
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Summary
run: |
echo "### Image published :whale:" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo "docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "Make it public: repo → Packages → aios → Package settings → Change visibility" \
>> $GITHUB_STEP_SUMMARY