Skip to content

Commit c441752

Browse files
committed
[Feat] ✨ Add Github Action To Build Binary & Docker image #3
1 parent b659f2a commit c441752

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

.github/workflows/build.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Build GPU Docker API
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
7+
jobs:
8+
build:
9+
name: build
10+
runs-on: ubuntu-latest
11+
if: github.repository == 'XShengTech/gpu-docker-api'
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version: 'stable'
19+
check-latest: true
20+
21+
- name: Build binary
22+
run: |
23+
BRANCH=$(git rev-parse --abbrev-ref HEAD)
24+
VERSION=$(git describe --tags | cut -d'-' -f1)
25+
COMMIT=$(git rev-parse --short HEAD)
26+
GO_VERSION=$(go env GOVERSION)
27+
BUILD_TIME=$(date +%FT%T%z)
28+
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X main.BRANCH=${BRANCH} -X main.VERSION=${VERSION} -X main.COMMIT=${COMMIT} -X main.GoVersion=${GO_VERSION} -X main.BuildTime=${BUILD_TIME}" -trimpath -o gpu-docker-api cmd/gpu-docker-api/main.go && tar -zcvf gpu-docker-api-linux-amd64.tar.gz gpu-docker-api
29+
GOOS=freebsd GOARCH=amd64 go build -ldflags="-s -w -X main.BRANCH=${BRANCH} -X main.VERSION=${VERSION} -X main.COMMIT=${COMMIT} -X main.GoVersion=${GO_VERSION} -X main.BuildTime=${BUILD_TIME}" -trimpath -o gpu-docker-api cmd/gpu-docker-api/main.go && tar -zcvf gpu-docker-api-freebsd-amd64.tar.gz gpu-docker-api
30+
- name: Create Release and Upload Release Asset
31+
uses: softprops/action-gh-release@v1
32+
with:
33+
files: |
34+
gpu-docker-api-linux-amd64.tar.gz
35+
gpu-docker-api-freebsd-amd64.tar.gz
36+
37+
docker-build:
38+
name: docker-build
39+
runs-on: ubuntu-latest
40+
permissions:
41+
packages: write
42+
contents: read
43+
steps:
44+
- uses: actions/checkout@v3
45+
46+
- name: Setup timezone
47+
uses: zcong1993/setup-timezone@master
48+
with:
49+
timezone: Asia/Shanghai
50+
51+
- name: Login to DockerHub
52+
uses: docker/login-action@v2
53+
with:
54+
username: ${{ secrets.DOCKERHUB_USERNAME }}
55+
password: ${{ secrets.DOCKERHUB_TOKEN }}
56+
57+
- name: Set up QEMU
58+
uses: docker/setup-qemu-action@v2
59+
60+
- name: Set up Docker Buildx
61+
uses: docker/setup-buildx-action@v2
62+
63+
- name: Build and push
64+
uses: docker/build-push-action@v4
65+
with:
66+
platforms: linux/amd64
67+
context: .
68+
file: ./Dockerfile
69+
push: true
70+
tags: |
71+
docker.io/xshengtech/gpu-docker-api:${{ github.ref_name }}
72+
docker.io/xshengtech/gpu-docker-api:latest

0 commit comments

Comments
 (0)