-
Notifications
You must be signed in to change notification settings - Fork 2
163 lines (154 loc) · 6.5 KB
/
docker-publish.yml
File metadata and controls
163 lines (154 loc) · 6.5 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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Publish Docker
on:
workflow_dispatch:
inputs:
version:
description: "Version name"
required: true
type: string
env:
# github.repository as <account>/<repo>
REGISTRY: docker.io
AILIYUN_REGISTRY: registry.cn-hongkong.aliyuncs.com
AILIYUN_MANAGER_IMAGE_NAME: snap_emu/manager
AILIYUN_API_IMAGE_NAME: snap_emu/api
MANAGER_IMAGE_NAME: heltec/snapemu-manager
API_IMAGE_NAME: heltec/snapemu-api
jobs:
build:
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
with:
cosign-release: 'v2.2.4'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
- uses: docker/setup-qemu-action@v3.2.0
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log into registry ${{ env.AILIYUN_REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.AILIYUN_REGISTRY }}
username: ${{ secrets.AILIYUN_DOCKER_USER }}
password: ${{ secrets.AILIYUN_DOCKER_PASSWORD }}
- name: Extract Docker metadata
id: meta-manager
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.MANAGER_IMAGE_NAME }}
- name: Extract Docker metadata
id: meta-api
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.API_IMAGE_NAME }}
- name: Extract Aliyun Docker metadata
id: aliyun-meta-manager
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.AILIYUN_REGISTRY }}/${{ env.AILIYUN_MANAGER_IMAGE_NAME }}
- name: Extract Aliyun Docker metadata
id: aliyun-meta-api
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.AILIYUN_REGISTRY }}/${{ env.AILIYUN_API_IMAGE_NAME }}
- name: Print tags
env:
TAGS: ${{ steps.meta-manager.outputs.tags }} ${{ steps.meta-api.outputs.tags }}
run: echo "${TAGS}"
- name: Setup Dockerfile
run: |
cat <<"EOF" > Dockerfile
FROM --platform=$BUILDPLATFORM rust:1.86.0-alpine3.21 AS builder
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ENV RUST_BACKTRACE=1
ENV SNAPEMU_DEVICE_VERSION=v1
ENV SNAPEMU_API_VERSION=v1
WORKDIR /usr/src/app
COPY . .
RUN apk add --no-cache musl-dev pkgconfig make perl protoc openssl-dev curl patch bash python3 g++ gcompat
RUN set -eux; \
case "$TARGETPLATFORM" in \
"linux/amd64") rustArch='x86_64-unknown-linux-musl';; \
"linux/arm64") rustArch='aarch64-unknown-linux-musl'; \
wget https://musl.cc/aarch64-linux-musl-cross.tgz; \
tar xf aarch64-linux-musl-cross.tgz; \
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER="$PWD/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc";; \
*) echo >&2 "unsupported architecture: $TARGETPLATFORM"; exit 1 ;; \
esac; \
rustup target add ${rustArch}; \
cargo build --target=${rustArch} --release; \
cp target/${rustArch}/release/snap_api /snap_api; \
cp target/${rustArch}/release/devices_manager /devices_manager;
FROM alpine:3.20.0 AS api
WORKDIR /usr/src/app
COPY --from=builder /snap_api ./
CMD [ "./snap_api" ]
FROM alpine:3.20.0 AS manager
WORKDIR /usr/src/app
COPY --from=builder /devices_manager ./
CMD [ "./devices_manager" ]
EOF
- name: Build and push manager Docker image
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
platforms: linux/amd64,linux/arm64/v8
context: .
target: manager
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-manager.outputs.tags }}
labels: ${{ steps.meta-manager.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push api Docker image
id: build-and-push-api
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
platforms: linux/amd64,linux/arm64/v8
context: .
target: api
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-api.outputs.tags }}
labels: ${{ steps.meta-api.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push manager Docker image
id: aliyun-build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
platforms: linux/amd64,linux/arm64/v8
context: .
target: manager
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.aliyun-meta-manager.outputs.tags }}
labels: ${{ steps.aliyun-meta-manager.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push api Docker image
id: aliyun-build-and-push-api
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
platforms: linux/amd64,linux/arm64/v8
context: .
target: api
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.aliyun-meta-api.outputs.tags }}
labels: ${{ steps.aliyun-meta-api.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max