Skip to content

Commit 9c6e73e

Browse files
committed
👷 Refactor docker build and update actions
1 parent 284e41b commit 9c6e73e

File tree

4 files changed

+36
-53
lines changed

4 files changed

+36
-53
lines changed

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
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:
127
- 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"
8+
with:
9+
sparse-checkout: |
10+
Dockerfile
11+
sparse-checkout-cone-mode: false
12+
- uses: actions/download-artifact@v4
13+
with:
14+
name: binary
15+
path: '${{ github.workspace }}/dist'
1816
- uses: docker/setup-qemu-action@v3
1917
- uses: docker/setup-buildx-action@v3
2018
- uses: docker/login-action@v3
@@ -27,7 +25,7 @@ runs:
2725
with:
2826
images: ghcr.io/${{ github.repository }}
2927
- id: push
30-
uses: docker/build-push-action@v5
28+
uses: docker/build-push-action@v6
3129
with:
3230
context: .
3331
target: yutu
@@ -36,11 +34,8 @@ runs:
3634
labels: ${{ steps.meta.outputs.labels }}
3735
platforms: linux/amd64,linux/arm64
3836
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
37+
sbom: true
38+
- uses: actions/attest-build-provenance@v2
4439
with:
4540
subject-name: ghcr.io/${{ github.repository }}
4641
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: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ jobs:
3131
- name: Upload artifact
3232
uses: actions/upload-artifact@v4
3333
with:
34-
path: dist
34+
name: binary
35+
path: dist/yutu_*/yutu-*
3536

3637
attestation:
3738
needs: [goreleaser]
@@ -44,19 +45,19 @@ jobs:
4445
fail-fast: false
4546
matrix:
4647
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
48+
- darwin_amd64_v1/yutu-darwin-amd64
49+
- darwin_arm64_v8.0/yutu-darwin-arm64
50+
- linux_amd64_v1/yutu-linux-amd64
51+
- linux_arm64_v8.0/yutu-linux-arm64
52+
- windows_amd64_v1/yutu-windows-amd64.exe
53+
- windows_arm64_v8.0/yutu-windows-arm64.exe
5354
steps:
5455
- name: Download artifact
5556
uses: actions/download-artifact@v4
5657
with:
57-
merge-multiple: true
58+
name: binary
5859
- name: Attest
59-
uses: actions/attest-build-provenance@v1
60+
uses: actions/attest-build-provenance@v2
6061
with:
6162
subject-path: '${{ github.workspace }}/yutu_${{ matrix.path }}'
6263

@@ -77,7 +78,7 @@ jobs:
7778
runs-on: macos-latest
7879
if: false
7980
steps:
80-
- uses: dawidd6/action-homebrew-bump-formula@v3
81+
- uses: dawidd6/action-homebrew-bump-formula@v4
8182
with:
8283
token: ${{ secrets.RELEASE_PAT }}
8384
tag: ${{ github.event.release.tag_name }}
@@ -95,5 +96,3 @@ jobs:
9596
id-token: write
9697
steps:
9798
- 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)