Browse Source

up build docker

ljw 1 year ago
parent
commit
d18d8c0e3f
3 changed files with 167 additions and 110 deletions
  1. 166 0
      .github/workflows/build.yml
  2. 0 83
      .github/workflows/release_arm64.yml
  3. 1 27
      Dockerfile

+ 166 - 0
.github/workflows/build.yml

@@ -0,0 +1,166 @@
1
+name: Build
2
+
3
+on:
4
+  workflow_dispatch:
5
+  push:
6
+    tags:
7
+      - 'v*.*.*'  # 当推送带有版本号的 tag(例如 v1.0.0)时触发工作流
8
+
9
+jobs:
10
+  build:
11
+    runs-on: ubuntu-latest
12
+
13
+    strategy:
14
+      fail-fast: false
15
+      matrix:
16
+        job:
17
+          - { platform: "amd64", goos: "linux" }
18
+          - { platform: "arm64v8", goos: "linux" }
19
+          - { platform: "amd64", goos: "windows" }
20
+
21
+    steps:
22
+      - name: Checkout code
23
+        uses: actions/checkout@v4
24
+
25
+      - name: Set up Go environment
26
+        uses: actions/setup-go@v4
27
+        with:
28
+          go-version: '1.22'  # 选择 Go 版本
29
+
30
+      - name: Set up npm
31
+        uses: actions/setup-node@v2
32
+        with:
33
+          node-version: '20'
34
+
35
+
36
+      - name: build rustdesk-api-web
37
+        run: |
38
+          git clone https://github.com/lejianwen/rustdesk-api-web
39
+          cd rustdesk-api-web
40
+          npm install
41
+          npm run build
42
+          mkdir ../resources/admin/ -p
43
+          cp -ar dist/* ../resources/admin/
44
+
45
+      - name: tidy
46
+        run: go mod tidy
47
+
48
+      - name: swag
49
+        run: |
50
+          go install github.com/swaggo/swag/cmd/swag@latest
51
+          swag init -g cmd/apimain.go --output docs/api --instanceName api --exclude http/controller/admin
52
+          swag init -g cmd/apimain.go --output docs/admin --instanceName admin --exclude http/controller/api
53
+
54
+      - name: Build for ${{ matrix.goos }}-${{ matrix.goarch }}
55
+        run: |
56
+          mkdir release -p
57
+          cp -ar resources release/
58
+          cp -ar docs release/
59
+          cp -ar conf release/
60
+          mkdir -p release/data
61
+          mkdir -p release/runtime
62
+          if [ "${{ matrix.goos }}" = "windows" ]; then
63
+            sudo apt-get install gcc-mingw-w64-x86-64 zip -y
64
+            GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CC=x86_64-w64-mingw32-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain.exe ./cmd/apimain.go
65
+            zip -r ${{ matrix.goos}}-${{ matrix.goarch }}.zip ./release
66
+          else
67
+            if [ "${{ matrix.platform }}" = "arm64v8" ]; then
68
+                wget https://musl.cc/aarch64-linux-musl-cross.tgz
69
+                tar -xvzf aarch64-linux-musl-cross.tgz
70
+                export PATH=$PATH:$PWD/aarch64-linux-musl-cross/bin
71
+                GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CC=aarch64-linux-musl-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain ./cmd/apimain.go
72
+            else
73
+              sudo apt-get install musl musl-dev musl-tools -y
74
+              GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CC=musl-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain ./cmd/apimain.go
75
+            fi
76
+            tar -czf ${{ matrix.goos}}-${{ matrix.goarch }}.tar.gz ./release
77
+          fi
78
+
79
+      - name: Upload artifact
80
+        uses: actions/upload-artifact@v4
81
+        with:
82
+          name: rustdesk-api-${{ matrix.goos }}-${{ matrix.goarch }}
83
+          path: |
84
+            ${{ matrix.goos}}-${{ matrix.goarch }}.tar.gz
85
+            ${{ matrix.goos}}-${{ matrix.goarch }}.zip
86
+
87
+      - name: Upload to GitHub Release
88
+        uses: softprops/action-gh-release@v2
89
+        with:
90
+          files: |
91
+            ${{ matrix.goos}}-${{ matrix.goarch }}.tar.gz
92
+            ${{ matrix.goos}}-${{ matrix.goarch }}.zip
93
+        env:
94
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95
+  docker:
96
+    name: Push Docker Image ${{ matrix.platform }}
97
+    needs: build
98
+    runs-on: ubuntu-latest
99
+    strategy:
100
+      fail-fast: false
101
+      matrix:
102
+        job:
103
+          - { platform: "amd64", goos: "linux",  docker_platform: "linux/amd64" }
104
+          - { platform: "arm64v8", goos: "linux",  docker_platform: "linux/arm64" }
105
+    steps:
106
+#      - name: Checkout code
107
+#        uses: actions/checkout@v4
108
+
109
+      - name: Log in to Docker Hub
110
+        uses: docker/login-action@v2
111
+        with:
112
+          username: ${{ secrets.DOCKER_USERNAME }}
113
+          password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
114
+
115
+      - name: Extract version from tag
116
+        id: vars
117
+        run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
118
+
119
+      - name: Download binaries
120
+        uses: actions/download-artifact@v3
121
+        with:
122
+          name: rustdesk-api-${{ matrix.goos }}-${{ matrix.goarch }}
123
+          path: rustdesk-api/
124
+
125
+      - name: Unzip binaries
126
+        run: |
127
+          tar -xzf rustdesk-api/rustdesk-api-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz -C rustdesk-api/
128
+
129
+      - name: Build and push Docker image
130
+        uses: docker/build-push-action@v5
131
+        with:
132
+          context: "."
133
+          file: ./Dockerfile
134
+          platforms: ${{ matrix.job.docker_platform }}
135
+          push: true
136
+          tags: |
137
+            lejianwen/rustdesk-api:latest-${{ matrix.job.platform }}
138
+            lejianwen/rustdesk-api:${{ env.TAG }}-${{ matrix.job.platform }}
139
+  docker-manifest:
140
+    name: Push Docker Manifest
141
+    needs: docker
142
+    runs-on: ubuntu-latest
143
+    steps:
144
+      - name: Extract version from tag
145
+        id: vars
146
+        run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
147
+
148
+      - name: Log in to Docker Hub
149
+        uses: docker/login-action@v2
150
+        with:
151
+          username: ${{ secrets.DOCKER_USERNAME }}
152
+          password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
153
+
154
+      - name: Create and push manifest (:version)
155
+        uses: Noelware/docker-manifest-action@master
156
+        with:
157
+          base-image: lejianwen/rustdesk-api:${{ env.TAG }}
158
+          extra-images: lejianwen/rustdesk-api:${{ env.TAG }}-amd64,lejianwen/rustdesk-api:${{ env.TAG }}-arm64v8
159
+          push: true
160
+
161
+#      - name: Create and push manifest (:latest)
162
+#        uses: Noelware/docker-manifest-action@master
163
+#        with:
164
+#          base-image: lejianwen/rustdesk-api:latest
165
+#          extra-images: lejianwen/rustdesk-api:latest-amd64,lejianwen/rustdesk-api:latest-arm64v8
166
+#          push: true

+ 0 - 83
.github/workflows/release_arm64.yml

@@ -1,83 +0,0 @@
1
-name: Build and Release Arm64
2
-
3
-#on:
4
-#  push:
5
-#    tags:
6
-#      - 'v*.*.*'  # 当推送带有版本号的 tag(例如 v1.0.0)时触发工作流
7
-on:
8
-  push:
9
-    branches: [ "master" ]
10
-#  pull_request:
11
-#    branches: [ "master" ]
12
-
13
-jobs:
14
-  build:
15
-    runs-on: ubuntu-latest
16
-
17
-    strategy:
18
-      matrix:
19
-        goos: [ linux ] # 指定要构建的操作系统
20
-        goarch: [ arm64 ]         # 指定架构
21
-
22
-    steps:
23
-      - name: Checkout code
24
-        uses: actions/checkout@v4
25
-
26
-      - name: Set up Go environment
27
-        uses: actions/setup-go@v4
28
-        with:
29
-          go-version: '1.22'  # 选择 Go 版本
30
-
31
-      - name: Set up npm
32
-        uses: actions/setup-node@v2
33
-        with:
34
-          node-version: '20'
35
-
36
-
37
-      - name: build rustdesk-api-web
38
-        run: |
39
-          git clone https://github.com/lejianwen/rustdesk-api-web
40
-          cd rustdesk-api-web
41
-          npm install
42
-          npm run build
43
-          mkdir ../resources/admin/ -p
44
-          cp -ar dist/* ../resources/admin/
45
-
46
-      - name: tidy
47
-        run: go mod tidy
48
-
49
-
50
-      - name: swag
51
-        run: |
52
-          go install github.com/swaggo/swag/cmd/swag@latest
53
-          swag init -g cmd/apimain.go --output docs/api --instanceName api --exclude http/controller/admin
54
-          swag init -g cmd/apimain.go --output docs/admin --instanceName admin --exclude http/controller/api
55
-
56
-      - name: Build for ${{ matrix.goos }}-${{ matrix.goarch }}
57
-        run: |
58
-          wget https://musl.cc/aarch64-linux-musl-cross.tgz
59
-          tar -xvzf aarch64-linux-musl-cross.tgz
60
-          export PATH=$PATH:$PWD/aarch64-linux-musl-cross/bin
61
-          mkdir release -p
62
-          cp -ar resources release/
63
-          cp -ar docs release/
64
-          cp -ar conf release/
65
-          mkdir -p release/data
66
-          mkdir -p release/runtime
67
-          GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CC=aarch64-linux-musl-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain ./cmd/apimain.go
68
-          tar -czf ${{ matrix.goos}}-${{ matrix.goarch }}.tar.gz ./release 
69
-
70
-      - name: Upload artifact
71
-        uses: actions/upload-artifact@v4
72
-        with:
73
-          name: myapp-${{ matrix.goos }}-${{ matrix.goarch }}
74
-          path: |
75
-            ${{ matrix.goos}}-${{ matrix.goarch }}.tar.gz
76
-
77
-#      - name: Upload to GitHub Release
78
-#        uses: softprops/action-gh-release@v2
79
-#        with:
80
-#          files: |
81
-#            ${{ matrix.goos}}-${{ matrix.goarch }}.tar.gz
82
-#        env:
83
-#          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

+ 1 - 27
Dockerfile

@@ -1,35 +1,9 @@
1 1
 FROM golang:1.22-alpine as builder
2 2
 
3
-RUN set -eux; \
4
-    apk add --no-cache git gcc  build-base sqlite-dev npm nodejs; \
5
-        git clone https://github.com/lejianwen/rustdesk-api-web; \
6
-        git clone https://github.com/lejianwen/rustdesk-api; \
7
-    #先编译后台
8
-        cd rustdesk-api-web; \
9
-        npm install; \
10
-        npm run build; \
11
-    cd ..; \
12
-        mkdir -p rustdesk-api/resources/admin; \
13
-        cp -ar rustdesk-api-web/dist/* rustdesk-api/resources/admin; \
14
-        cd rustdesk-api; \
15
-        go mod tidy; \
16
-        go install github.com/swaggo/swag/cmd/swag@latest; \
17
-    swag init -g cmd/apimain.go --output docs/api --instanceName api --exclude http/controller/admin; \
18
-    swag init -g cmd/apimain.go --output docs/admin --instanceName admin --exclude http/controller/api; \
19
-    go env -w GO111MODULE=on;\
20
-    CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain ./cmd/apimain.go; \
21
-    cp -ar resources release/; \
22
-    mkdir -p release/resources/public; \
23
-    cp -ar docs release/; \
24
-    cp -ar conf release/; \
25
-    mkdir -p release/data; \
26
-    mkdir -p release/runtime;
27
-
28
-
29 3
 FROM alpine
30 4
 WORKDIR /app
31 5
 RUN apk add --no-cache tzdata
32
-COPY --from=builder /go/rustdesk-api/release /app/
6
+COPY rustdesk-api/release /app/
33 7
 VOLUME /app/data
34 8
 
35 9
 EXPOSE 21114