Skip to content

Commit 8192d80

Browse files
committed
👷 Refactor docker build and update actions
1 parent 86a4516 commit 8192d80

File tree

4 files changed

+28
-54
lines changed

4 files changed

+28
-54
lines changed

‎.github/actions/github-packages/action.yml‎

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
name: Release to GitHub Packages
22
description: Release to GitHub Packages
33

4-
inputs:
5-
version:
6-
description: 'The version of the package'
7-
required: true
8-
94
runs:
105
using: composite
116
steps:
12-
- uses: actions/checkout@v4
13-
- id: ldflags
14-
shell: bash
15-
run: |
16-
echo "commit-date=$(git log -1 --date='format:%Y-%m-%d/%H.%M.%S' --pretty=%cd)" >> "$GITHUB_OUTPUT"
17-
echo "commit=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
7+
- uses: actions/download-artifact@v4
8+
with:
9+
path: '${{ github.workspace }}/dist'
1810
- uses: docker/setup-qemu-action@v3
1911
- uses: docker/setup-buildx-action@v3
2012
- uses: docker/login-action@v3
@@ -27,7 +19,7 @@ runs:
2719
with:
2820
images: ghcr.io/${{ github.repository }}
2921
- id: push
30-
uses: docker/build-push-action@v5
22+
uses: docker/build-push-action@v6
3123
with:
3224
context: .
3325
target: yutu
@@ -36,11 +28,8 @@ runs:
3628
labels: ${{ steps.meta.outputs.labels }}
3729
platforms: linux/amd64,linux/arm64
3830
provenance: true
39-
build-args: |
40-
version=${{ inputs.version }}
41-
commit=${{ steps.ldflags.outputs.commit }}
42-
commitDate=${{ steps.ldflags.outputs.commit-date }}
43-
- uses: actions/attest-build-provenance@v1
31+
sbom: true
32+
- uses: actions/attest-build-provenance@v2
4433
with:
4534
subject-name: ghcr.io/${{ github.repository }}
4635
subject-digest: ${{ steps.push.outputs.digest }}

‎.github/workflows/greetings.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ jobs:
1212
steps:
1313
- uses: actions/[email protected]
1414
with:
15-
repo-token: ${{ secrets.GITHUB_TOKEN }}
15+
repo-token: ${{ github.token }}
1616
issue-message: "Welcome to yutu, thank you for opening your first issue!"
1717
pr-message: "Welcome to yutu, thank you for opening your first PR!"

‎.github/workflows/publish.yml‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,17 @@ jobs:
4444
fail-fast: false
4545
matrix:
4646
path:
47-
- darwin_amd64_v1/yutu
48-
- darwin_arm64/yutu
49-
- linux_amd64_v1/yutu
50-
- linux_arm64/yutu
51-
- windows_amd64_v1/yutu.exe
52-
- windows_arm64/yutu.exe
47+
- darwin_amd64_v1/yutu-darwin-amd64
48+
- darwin_arm64_v8.0/yutu-darwin-arm64
49+
- linux_amd64_v1/yutu-linux-amd64
50+
- linux_arm64_v8.0/yutu-linux-arm64
51+
- windows_amd64_v1/yutu-windows-amd64.exe
52+
- windows_arm64_v8.0/yutu-windows-arm64.exe
5353
steps:
5454
- name: Download artifact
5555
uses: actions/download-artifact@v4
56-
with:
57-
merge-multiple: true
5856
- name: Attest
59-
uses: actions/attest-build-provenance@v1
57+
uses: actions/attest-build-provenance@v2
6058
with:
6159
subject-path: '${{ github.workspace }}/yutu_${{ matrix.path }}'
6260

@@ -77,7 +75,7 @@ jobs:
7775
runs-on: macos-latest
7876
if: false
7977
steps:
80-
- uses: dawidd6/action-homebrew-bump-formula@v3
78+
- uses: dawidd6/action-homebrew-bump-formula@v4
8179
with:
8280
token: ${{ secrets.RELEASE_PAT }}
8381
tag: ${{ github.event.release.tag_name }}
@@ -95,5 +93,3 @@ jobs:
9593
id-token: write
9694
steps:
9795
- uses: eat-pray-ai/yutu/.github/actions/github-packages@main
98-
with:
99-
version: ${{ github.event.release.tag_name }}

‎Dockerfile‎

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
1-
FROM golang:alpine as builder
2-
ARG commit
3-
ARG commitDate
4-
ARG version
5-
6-
ENV MOD="github.com/eat-pray-ai/yutu/cmd"
7-
WORKDIR /app
8-
COPY . .
9-
10-
RUN Version="${MOD}.Version=${version}" \
11-
Commit="${MOD}.Commit=${commit}" \
12-
CommitDate="${MOD}.CommitDate=${commitDate}" \
13-
Os="${MOD}.Os=linux" \
14-
Arch="${MOD}.Arch=$(go env GOARCH)" \
15-
ldflags="-s -X ${Version} -X ${Commit} -X ${CommitDate} -X ${Os} -X ${Arch}" \
16-
&& export ldflags \
17-
&& go mod download \
18-
&& go build -ldflags "${ldflags}" -o yutu .
19-
20-
FROM alpine:latest as yutu
21-
22-
COPY --from=builder /app/yutu /usr/local/bin/yutu
23-
RUN chmod +x /usr/local/bin/yutu
24-
1+
FROM alpine:latest AS binary
2+
ARG TARGETARCH
3+
4+
COPY dist /app/
5+
RUN if [[ "${TARGETARCH}" == "arm64" ]]; then \
6+
mv /app/yutu_linux_arm64_v8.0/yutu-linux-arm64 /app/yutu; \
7+
elif [[ "${TARGETARCH}" == "amd64" ]]; then \
8+
mv /app/yutu_linux_amd64_v1/yutu-linux-amd64 /app/yutu; \
9+
fi && \
10+
chmod +x /app/yutu
11+
12+
FROM scratch AS yutu
13+
COPY --from=binary /app/yutu /usr/local/bin/yutu
2514
ENTRYPOINT ["/usr/local/bin/yutu"]

0 commit comments

Comments
 (0)