-
Notifications
You must be signed in to change notification settings - Fork 7
102 lines (93 loc) · 3.16 KB
/
docker-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
name: Docker
on:
schedule:
- cron: '37 18 * * 0'
push:
branches: [ "main" ]
# Publish semver tags as releases.
tags: [ "**" ]
env:
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:
Build:
uses: ./.github/workflows/build.yml
with:
skip-windows: true
skip-macos: true
skip-linux-musl: true
skip-android: true
Docker:
needs: Build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Create Dockerfile
run: |
cat <<EOF > Dockerfile
# syntax=docker/dockerfile:1
FROM scratch AS binary-amd64
COPY artifacts/hath-rust-x86_64-unknown-linux-gnu/hath-rust /hath-rust
FROM scratch AS binary-arm64
COPY artifacts/hath-rust-aarch64-unknown-linux-gnu/hath-rust /hath-rust
FROM scratch AS binary-arm
COPY artifacts/hath-rust-armv7-unknown-linux-gnueabihf/hath-rust /hath-rust
FROM binary-\$TARGETARCH AS binary
FROM debian:bookworm-slim
WORKDIR /hath
COPY --from=binary --chmod=755 /hath-rust /usr/local/bin/hath-rust
ENTRYPOINT ["hath-rust"]
EOF
- name: Download artifact
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
env:
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
with:
images: |
ghcr.io/${{ env.IMAGE_NAME }}
${{ env.IMAGE_NAME }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
cache-from: type=gha
cache-to: type=gha,mode=max