From c42f9637fbd6855e1b0a2798489d1d30969b79e7 Mon Sep 17 00:00:00 2001 From: DDSRem <73049927+DDSRem@users.noreply.github.com> Date: Mon, 22 Jul 2024 13:57:24 +0800 Subject: [PATCH] feat: refactor ci - Docker images support amd64 and arm64 architectures - The web interface is built using github actions - Use Alpine as the base image to compress the image size --- .github/workflows/go.yml | 26 +++++++++++++++++++++++++- Dockerfile | 24 +++++------------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 68b5858..5809041 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -9,7 +9,14 @@ jobs: build_and_deploy_docker: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + + - name: Set Up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set Up Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to image repository uses: docker/login-action@v2 with: @@ -17,9 +24,26 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GHCR_TOKEN }} + - name: Set up Flutter + uses: subosito/flutter-action@v2 + with: + channel: stable + flutter-version: 3 + + - name: Build Web + run: | + cd ui + flutter pub get + flutter build web + - name: Build and push uses: docker/build-push-action@v3 with: + context: . + file: Dockerfile + platforms: | + linux/amd64 + linux/arm64 push: true tags: ghcr.io/simon-ding/polaris:latest diff --git a/Dockerfile b/Dockerfile index 178c435..c4d4266 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,4 @@ -FROM instrumentisto/flutter:3 AS flutter -WORKDIR /app -COPY ./ui/pubspec.yaml ./ui/pubspec.lock ./ -RUN flutter pub get -COPY ./ui/ ./ -RUN flutter build web - - -# 打包依赖阶段使用golang作为基础镜像 -FROM golang:1.22 as builder +FROM golang:1.22-alpine3.20 as builder # 启用go module ENV GO111MODULE=on \ @@ -15,22 +6,17 @@ ENV GO111MODULE=on \ WORKDIR /app -COPY go.mod . -COPY go.sum . +COPY go.mod go.sum ./ RUN go mod download COPY . . +RUN go build -o polaris ./cmd/ -COPY --from=flutter /app/build/web ./ui/build/web/ -# 指定OS等,并go build -RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -o polaris ./cmd/ - -FROM debian:12 +FROM alpine:3.20 WORKDIR /app -RUN apt-get update && apt-get -y install ca-certificates +RUN apk add --no-cache bash ca-certificates -# 将上一个阶段publish文件夹下的所有文件复制进来 COPY --from=builder /app/polaris . EXPOSE 8080