ngbs 3 years ago
parent
commit
0e092ad285
3 changed files with 113 additions and 0 deletions
  1. 82 0
      .github/workflows/build-air-universe.yml
  2. 17 0
      air-universe/Dockerfile
  3. 14 0
      air-universe/Dockerfile.latest

+ 82 - 0
.github/workflows/build-air-universe.yml

@@ -0,0 +1,82 @@
+name: Build Air-Universe
+
+on:
+  # push:
+    # branches: [ master ]
+    # paths:
+    #   - 'air-universe/**'
+    #   - '.github/workflows/build-air-universe.yml'
+  # UTC +8
+  # schedule:
+  #   - cron: "0 20 * * *"
+  # pull_request:
+  #   branches: [ master ]
+  workflow_dispatch:
+
+jobs:
+  build-air-universe:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Set Variables
+        run: |
+          echo "AU_PRE_VERSION=$(curl -fsSL https://api.github.com/repos/crossfw/Air-Universe/tags | grep '"name":' | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/v//g;s/,//g;s/ //g')" >> $GITHUB_ENV
+          echo "AU_VERSION=$(curl -fsSL https://api.github.com/repos/crossfw/Air-Universe/releases/latest | grep '"tag_name":' | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/v//g;s/,//g;s/ //g')" >> $GITHUB_ENV
+        shell: bash
+
+      - name: Check Out Repo
+        uses: actions/checkout@v3
+
+      - name: Set up Docker Buildx
+        uses: docker/setup-buildx-action@v2
+        id: buildx
+
+      - name: Cache Docker layers
+        uses: actions/cache@v3
+        with:
+          path: /tmp/.buildx-cache
+          key: ${{ runner.os }}-buildx-${{ github.sha }}
+          restore-keys: |
+            ${{ runner.os }}-buildx-
+
+      - name: Login to Docker Hub
+        uses: docker/login-action@v2
+        with:
+          username: ${{ secrets.DOCKER_HUB_USERNAME }}
+          password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
+
+      - name: Build and push Docker images
+        uses: docker/build-push-action@v3
+        id: docker_build_air-universe_core_pre
+        with:
+          context: ./air-universe
+          file: ./air-universe/Dockerfile
+          push: true
+          tags: |
+            ${{ secrets.DOCKER_HUB_USERNAME }}/air-universe:${{ env.AU_PRE_VERSION }}
+          builder: ${{ steps.buildx.outputs.name }}
+          cache-from: type=local,src=/tmp/.buildx-cache
+          cache-to: type=local,dest=/tmp/.buildx-cache-new
+
+      - name: Build and push Docker images
+        uses: docker/build-push-action@v3
+        id: docker_build_air-universe_core
+        with:
+          context: ./air-universe
+          file: ./air-universe/Dockerfile.latest
+          push: true
+          tags: |
+            ${{ secrets.DOCKER_HUB_USERNAME }}/air-universe:latest
+            ${{ secrets.DOCKER_HUB_USERNAME }}/air-universe:${{ env.AU_VERSION }}
+          builder: ${{ steps.buildx.outputs.name }}
+          cache-from: type=local,src=/tmp/.buildx-cache
+          cache-to: type=local,dest=/tmp/.buildx-cache-new
+
+      - name: Move cache
+        run: |
+          rm -rf /tmp/.buildx-cache
+          mv /tmp/.buildx-cache-new /tmp/.buildx-cache
+
+      - name: Image digest
+        run: |
+          echo ${{ steps.docker_build_air-universe_core_pre.outputs.digest }}
+          echo ${{ steps.docker_build_air-universe_core.outputs.digest }}

+ 17 - 0
air-universe/Dockerfile

@@ -0,0 +1,17 @@
+# syntax=docker/dockerfile:1
+FROM golang:1.18.1-alpine AS builder
+WORKDIR /go/src
+ENV CGO_ENABLED=0
+RUN apk --no-cache add git && \
+    git clone https://github.com/crossfw/Air-Universe.git && cd cmd/Air-Universe && \
+    go mod download && \
+    go env -w GOFLAGS=-buildvcs=false && \
+    go build -v -o au -trimpath -ldflags "-s -w -buildid="
+
+FROM alpine
+RUN apk --update --no-cache add tzdata ca-certificates && \
+    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
+    mkdir /etc/au/ && mkdir -p /usr/local/share/au/
+COPY --from=builder /go/src/Air-Universe/cmd/Air-Universe/au /usr/local/bin
+
+ENTRYPOINT [ "au", "-c", "/etc/au/config.json"]

+ 14 - 0
air-universe/Dockerfile.latest

@@ -0,0 +1,14 @@
+# syntax=docker/dockerfile:1
+FROM golang:alpine AS builder
+WORKDIR /go/src
+ENV CGO_ENABLED=0
+RUN apk --no-cache add git && \
+    git clone https://github.com/crossfw/Air-Universe.git && cd cmd/Air-Universe && \
+    go mod download && \
+    go env -w GOFLAGS=-buildvcs=false && \
+    go build -v -o au -trimpath -ldflags "-s -w -buildid="
+
+FROM playn/alpine
+COPY --from=builder /go/src/Air-Universe/cmd/Air-Universe/au /usr/local/bin
+
+ENTRYPOINT [ "au", "-c", "/etc/au/config.json"]