Skip to content

Commit

Permalink
Optimized workflows ci and dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Cairry committed Feb 17, 2025
1 parent 258cb07 commit 5d695bf
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 63 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/release-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI

on:
push:
tags:
- v*

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker-container

- name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set env variables
id: set_env
run: |
echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
build-args: |
VERSION=${{ env.TAG_NAME }}
tags: |
cairry/watchalert:latest
cairry/watchalert:${{ env.TAG_NAME }}
34 changes: 0 additions & 34 deletions .github/workflows/release-drafter.yml

This file was deleted.

27 changes: 4 additions & 23 deletions .github/workflows/ci.yml → .github/workflows/test-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@ name: CI
on:
push:
branches:
- master
- '*/*'

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
arch:
- amd64
- arm64

steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -40,32 +34,19 @@ jobs:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to Aliyun Hub
uses: docker/login-action@v3
with:
registry: registry.cn-hangzhou.aliyuncs.com
username: ${{ secrets.OPSRE_ALIHUB_USERNAME }}
password: ${{ secrets.OPSRE_ALIHUB_TOKEN }}

- name: Set env variables
id: set_env
run: |
echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
echo "SHORT_SHA=${GITHUB_SHA:0:4}" >> $GITHUB_ENV
echo "DATE=$(TZ=Asia/Shanghai date +%Y-%m-%d.%H-%M-%S)" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/${{ matrix.arch }}
push: ${{ github.event_name != 'pull_request' }}
platforms: linux/amd64,linux/arm64
push: true
build-args: |
VERSION=${{ env.DATE }}
TARGETARCH=${{ matrix.arch }}
tags: |
cairry/watchalert:latest
cairry/watchalert:${{ env.BRANCH_NAME }}.${{ env.DATE }}.${{ env.SHORT_SHA }}
registry.cn-hangzhou.aliyuncs.com/opsre/watchalert:latest
registry.cn-hangzhou.aliyuncs.com/opsre/watchalert:${{ env.BRANCH_NAME }}.${{ env.DATE }}.${{ env.SHORT_SHA }}
cairry/watchalert:${{ env.BRANCH_NAME }}
11 changes: 5 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM --platform=$BUILDPLATFORM golang:1.21.9-alpine3.19 AS build
FROM golang:1.21.9-alpine3.19 AS build

ARG VERSION
ARG TARGETARCH

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

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

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

FROM alpine:3.19

COPY --from=build /root/watchAlert /app/watchAlert
COPY --from=build /root/w8t /app/w8t

WORKDIR /app

ENTRYPOINT ["/app/watchAlert"]
ENTRYPOINT ["/app/w8t"]

0 comments on commit 5d695bf

Please sign in to comment.