Skip to content

Commit 5d695bf

Browse files
committed
Optimized workflows ci and dockerfile
1 parent 258cb07 commit 5d695bf

File tree

4 files changed

+62
-63
lines changed

4 files changed

+62
-63
lines changed

.github/workflows/release-ci.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
- name: Set up QEMU
17+
uses: docker/setup-qemu-action@v3
18+
19+
- name: Inject slug/short variables
20+
uses: rlespinasse/github-slug-action@v4
21+
22+
- name: Set up Docker Buildx
23+
id: buildx
24+
uses: docker/setup-buildx-action@v3
25+
with:
26+
driver: docker-container
27+
28+
- name: Available platforms
29+
run: echo ${{ steps.buildx.outputs.platforms }}
30+
31+
- name: Login to Docker Hub
32+
uses: docker/login-action@v3
33+
with:
34+
username: ${{ secrets.DOCKERHUB_USER }}
35+
password: ${{ secrets.DOCKERHUB_TOKEN }}
36+
37+
- name: Set env variables
38+
id: set_env
39+
run: |
40+
echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
41+
42+
- name: Build and push
43+
uses: docker/build-push-action@v6
44+
with:
45+
context: .
46+
file: ./Dockerfile
47+
platforms: linux/amd64,linux/arm64
48+
push: true
49+
build-args: |
50+
VERSION=${{ env.TAG_NAME }}
51+
tags: |
52+
cairry/watchalert:latest
53+
cairry/watchalert:${{ env.TAG_NAME }}

.github/workflows/release-drafter.yml

-34
This file was deleted.

.github/workflows/ci.yml .github/workflows/test-ci.yml

+4-23
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@ name: CI
33
on:
44
push:
55
branches:
6-
- master
6+
- '*/*'
77

88
jobs:
99
build:
1010
runs-on: ubuntu-latest
1111

12-
strategy:
13-
matrix:
14-
arch:
15-
- amd64
16-
- arm64
17-
1812
steps:
1913
- name: Checkout code
2014
uses: actions/checkout@v3
@@ -40,32 +34,19 @@ jobs:
4034
username: ${{ secrets.DOCKERHUB_USER }}
4135
password: ${{ secrets.DOCKERHUB_TOKEN }}
4236

43-
- name: Login to Aliyun Hub
44-
uses: docker/login-action@v3
45-
with:
46-
registry: registry.cn-hangzhou.aliyuncs.com
47-
username: ${{ secrets.OPSRE_ALIHUB_USERNAME }}
48-
password: ${{ secrets.OPSRE_ALIHUB_TOKEN }}
49-
5037
- name: Set env variables
5138
id: set_env
5239
run: |
5340
echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
54-
echo "SHORT_SHA=${GITHUB_SHA:0:4}" >> $GITHUB_ENV
55-
echo "DATE=$(TZ=Asia/Shanghai date +%Y-%m-%d.%H-%M-%S)" >> $GITHUB_ENV
5641
5742
- name: Build and push
5843
uses: docker/build-push-action@v6
5944
with:
6045
context: .
6146
file: ./Dockerfile
62-
platforms: linux/${{ matrix.arch }}
63-
push: ${{ github.event_name != 'pull_request' }}
47+
platforms: linux/amd64,linux/arm64
48+
push: true
6449
build-args: |
6550
VERSION=${{ env.DATE }}
66-
TARGETARCH=${{ matrix.arch }}
6751
tags: |
68-
cairry/watchalert:latest
69-
cairry/watchalert:${{ env.BRANCH_NAME }}.${{ env.DATE }}.${{ env.SHORT_SHA }}
70-
registry.cn-hangzhou.aliyuncs.com/opsre/watchalert:latest
71-
registry.cn-hangzhou.aliyuncs.com/opsre/watchalert:${{ env.BRANCH_NAME }}.${{ env.DATE }}.${{ env.SHORT_SHA }}
52+
cairry/watchalert:${{ env.BRANCH_NAME }}

Dockerfile

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
FROM --platform=$BUILDPLATFORM golang:1.21.9-alpine3.19 AS build
1+
FROM golang:1.21.9-alpine3.19 AS build
22

33
ARG VERSION
4-
ARG TARGETARCH
54

65
ENV GOPROXY=https://goproxy.cn,direct
76

@@ -13,13 +12,13 @@ RUN sed -i "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g" /etc/apk/repositories
1312
&& apk upgrade && apk add --no-cache --virtual .build-deps \
1413
ca-certificates upx
1514

16-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build --ldflags="-X main.Version=${VERSION}" -o watchAlert . \
17-
&& chmod +x watchAlert
15+
RUN CGO_ENABLED=0 go build --ldflags="-X main.Version=${VERSION}" -o w8t . \
16+
&& chmod +x w8t
1817

1918
FROM alpine:3.19
2019

21-
COPY --from=build /root/watchAlert /app/watchAlert
20+
COPY --from=build /root/w8t /app/w8t
2221

2322
WORKDIR /app
2423

25-
ENTRYPOINT ["/app/watchAlert"]
24+
ENTRYPOINT ["/app/w8t"]

0 commit comments

Comments
 (0)