diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..68b5858 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,32 @@ +name: build + +on: + push: + branches: [ main ] + +jobs: + + build_and_deploy_docker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Login to image repository + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GHCR_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v3 + with: + push: true + tags: ghcr.io/simon-ding/polaris:latest + + # - name: Set up Go + # uses: actions/setup-go@v3 + # with: + # go-version: '>=1.20.0' + + # - name: Build + # run: go build -v ./... \ No newline at end of file diff --git a/.gitignore b/.gitignore index a3293d4..10047f6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ *.dll *.so *.dylib -*.yml +config.yml .idea/ .DS_Store *.db diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..37a7669 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,59 @@ +FROM ubuntu:20.04 as flutter_build + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update +RUN apt-get install -y curl git wget unzip libgconf-2-4 gdb libstdc++6 libglu1-mesa fonts-droid-fallback python3 +RUN apt-get clean + + +# download Flutter SDK from Flutter Github repo +RUN git clone https://github.com/flutter/flutter.git /usr/local/flutter + +# Set flutter environment path +ENV PATH="/usr/local/flutter/bin:/usr/local/flutter/bin/cache/dart-sdk/bin:${PATH}" + +# Run flutter doctor +RUN flutter doctor + +# Enable flutter web +RUN flutter channel stable +RUN flutter upgrade +RUN flutter config --enable-web + +# Copy files to container and build +RUN mkdir /app/ +COPY . /app/ +WORKDIR /app/ +RUN flutter build web + + +# 打包依赖阶段使用golang作为基础镜像 +FROM golang:1.20 as builder + +# 启用go module +ENV GO111MODULE=on \ + GOPROXY=https://goproxy.cn,direct + +WORKDIR /app + +COPY --from=flutter_build go.mod . +COPY --from=flutter_build go.sum . +RUN go mod download + +COPY --from=flutter_build . . + +# 指定OS等,并go build +RUN GOOS=linux GOARCH=amd64 go build -o polaris ./cmd/ + +FROM debian:12 + +WORKDIR /app +RUN apt-get update && apt-get -y install ca-certificates + +# 将上一个阶段publish文件夹下的所有文件复制进来 +COPY --from=builder /app/polaris . + +EXPOSE 8080 + +ENTRYPOINT ["./polaris"] \ No newline at end of file