diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 32e6723..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,444 +0,0 @@ -name: Build - -on: - workflow_dispatch: - inputs: - BASE_IMAGE_NAMESPACE: - description: 'Base image namespace (Default: Your Github username)' - required: false - default: '' - DOCKERHUB_IMAGE_NAMESPACE: - description: 'Docker Hub image namespace (Default: Your Github username)' - required: false - default: '' - GHCR_IMAGE_NAMESPACE: - description: 'GitHub Container Registry image namespace (Default: Your Github username)' - required: false - default: '' - SKIP_DOCKER_HUB: - description: 'Set to true to skip pushing to Docker Hub (default: false)' - required: false - default: 'false' - SKIP_GHCR: - description: 'Set to true to skip pushing to GHCR (default: false)' - required: false - default: 'false' - WEBCLIENT_SOURCE_LOCATION: - description: 'Web Client API Repository' - required: true - default: 'https://github.com/lejianwen/rustdesk-api-web' - push: - tags: - - 'v*.*.*' # 当推送带有版本号的 tag(例如 v1.0.0)时触发工作流 - - 'test*' - -env: - LATEST_TAG: latest - WEBCLIENT_SOURCE_LOCATION: ${{ github.event.inputs.WEBCLIENT_SOURCE_LOCATION || 'https://github.com/lejianwen/rustdesk-api-web' }} - BASE_IMAGE_NAMESPACE: ${{ github.event.inputs.BASE_IMAGE_NAMESPACE || github.actor }} - DOCKERHUB_IMAGE_NAMESPACE: ${{ github.event.inputs.DOCKERHUB_IMAGE_NAMESPACE || github.actor }} - GHCR_IMAGE_NAMESPACE: ${{ github.event.inputs.GHCR_IMAGE_NAMESPACE || github.actor }} - SKIP_DOCKER_HUB: ${{ github.event.inputs.SKIP_DOCKER_HUB || 'false' }} - SKIP_GHCR: ${{ github.event.inputs.SKIP_GHCR || 'false' }} -jobs: - build: - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - job: - - { platform: "amd64", goos: "linux", file_ext: "tar.gz" } - - { platform: "arm64", goos: "linux", file_ext: "tar.gz" } - - { platform: "armv7l", goos: "linux", file_ext: "tar.gz" } - - { platform: "amd64", goos: "windows", file_ext: "zip" } - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - uses: actions/checkout@v4 - with: - repository: lejianwen/rustdesk-api-web - path: rustdesk-api-web - ref: master - - - name: Set up Go environment - uses: actions/setup-go@v4 - with: - go-version: '1.23' # 选择 Go 版本 - - - name: Set up npm - uses: actions/setup-node@v2 - with: - node-version: '20' - - - name: build rustdesk-api-web - working-directory: rustdesk-api-web - run: | - npm install - npm run build - mkdir -p ../resources/admin/ - cp -ar dist/* ../resources/admin/ - - - name: tidy - run: go mod tidy - - - name: Get tag version - run: | - TAG_VERSION="${GITHUB_REF##*/}" - VERSION="${TAG_VERSION#v}" - echo "VERSION=$VERSION" >> $GITHUB_ENV - - - name: Write version to resources/version - run: echo $VERSION > resources/version - - - name: swag - run: | - go install github.com/swaggo/swag/cmd/swag@latest - swag init -g cmd/apimain.go --output docs/api --instanceName api --exclude http/controller/admin - swag init -g cmd/apimain.go --output docs/admin --instanceName admin --exclude http/controller/api - - - name: Build for ${{ matrix.job.goos }}-${{ matrix.job.platform }} - run: | - mkdir release -p - cp -ar resources release/ - cp -ar docs release/ - cp -ar conf release/ - mkdir -p release/data - mkdir -p release/runtime - if [ "${{ matrix.job.goos }}" = "windows" ]; then - sudo apt-get install gcc-mingw-w64-x86-64 zip -y - GOOS=${{ matrix.job.goos }} GOARCH=${{ matrix.job.platform }} CC=x86_64-w64-mingw32-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain.exe ./cmd/apimain.go - echo @echo off > release/start.bat - echo cmd /c \"%~dp0apimain.exe\" >> release/start.bat - zip -r ${{ matrix.job.goos}}-${{ matrix.job.platform }}.${{matrix.job.file_ext}} ./release - else - if [ "${{ matrix.job.platform }}" = "arm64" ]; then - wget https://musl.ljw.red/aarch64-linux-musl-cross.tgz - tar -xf aarch64-linux-musl-cross.tgz - export PATH=$PATH:$PWD/aarch64-linux-musl-cross/bin - GOOS=${{ matrix.job.goos }} GOARCH=${{ matrix.job.platform }} CC=aarch64-linux-musl-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain ./cmd/apimain.go - elif [ "${{ matrix.job.platform }}" = "armv7l" ]; then - wget https://musl.ljw.red/armv7l-linux-musleabihf-cross.tgz - tar -xf armv7l-linux-musleabihf-cross.tgz - export PATH=$PATH:$PWD/armv7l-linux-musleabihf-cross/bin - GOOS=${{ matrix.job.goos }} GOARCH=arm GOARM=7 CC=armv7l-linux-musleabihf-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain ./cmd/apimain.go - else - sudo apt-get install musl musl-dev musl-tools -y - GOOS=${{ matrix.job.goos }} GOARCH=${{ matrix.job.platform }} CC=musl-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain ./cmd/apimain.go - fi - tar -czf ${{ matrix.job.goos}}-${{ matrix.job.platform }}.${{matrix.job.file_ext}} ./release - fi - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: rustdesk-api-${{ matrix.job.goos }}-${{ matrix.job.platform }} - path: | - ${{ matrix.job.goos}}-${{ matrix.job.platform }}.${{matrix.job.file_ext}} - - - name: Upload to GitHub Release - uses: softprops/action-gh-release@v2 - with: - files: | - ${{ matrix.job.goos}}-${{ matrix.job.platform }}.${{matrix.job.file_ext}} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Generate Changelog - if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push' - run: npx changelogithub # or changelogithub@0.12 if ensure the stable result - env: - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} - - deb-package: - name: debian package - ${{ matrix.job.platform }} - needs: build - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - job: - - { platform: "amd64", goos: "linux", debian_platform: "amd64", crossbuild_package: ""} - - { platform: "arm64", goos: "linux", debian_platform: "arm64", crossbuild_package: "crossbuild-essential-arm64" } - - { platform: "armv7l", goos: "linux", debian_platform: "armhf", crossbuild_package: "crossbuild-essential-armhf" } - steps: - - - name: Checkout - uses: actions/checkout@v3 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Create packaging env - run: | - sudo apt update - DEBIAN_FRONTEND=noninteractive sudo apt install -y devscripts build-essential debhelper pkg-config ${{ matrix.job.crossbuild_package }} - mkdir -p debian-build/${{ matrix.job.platform }}/bin - - - name: Get tag version - id: get_tag - run: | - TAG_VERSION="${GITHUB_REF##*/}" - VERSION="${TAG_VERSION#v}" - echo "TAG_VERSION=$TAG_VERSION" >> $GITHUB_ENV - echo "VERSION=$VERSION" >> $GITHUB_ENV - - - name: Update changelog - run: | - DATE=$(date -R) - sed -i "1i rustdesk-api-server (${VERSION}) stable; urgency=medium\n\n * Automatically generated release for version ${VERSION}.\n\n -- GitHub Actions ${DATE}\n" debian/changelog - - - name: Download binaries - uses: actions/download-artifact@v4 - with: - name: rustdesk-api-${{ matrix.job.goos }}-${{ matrix.job.platform }} - path: . - - - name: Unzip binaries - run: | - mkdir -p ${{ matrix.job.platform }} - tar -xzf ${{ matrix.job.goos }}-${{ matrix.job.platform }}.tar.gz -C ${{ matrix.job.platform }} - - - name: Build package for ${{ matrix.job.platform }} arch - run: | - mv ${{ matrix.job.platform }}/release/apimain debian-build/${{ matrix.job.platform }}/bin/rustdesk-api - mv ${{ matrix.job.platform }}/release/resources/admin resources - chmod -v a+x debian-build/${{ matrix.job.platform }}/bin/* - mkdir -p data - cp -vr debian systemd conf data resources runtime debian-build/${{ matrix.job.platform }}/ - cat debian/control.tpl | sed 's/{{ ARCH }}/${{ matrix.job.debian_platform }}/' > debian-build/${{ matrix.job.platform }}/debian/control - cd debian-build/${{ matrix.job.platform }}/ - debuild -i -us -uc -b -a${{ matrix.job.debian_platform}} - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: rustdesk-api-${{ matrix.job.debian_platform }} - path: | - debian-build/*.deb - - - name: Create Release - uses: softprops/action-gh-release@v2 - with: - files: | - debian-build/rustdesk-api-server_*_${{ matrix.job.debian_platform }}.deb - - docker: - name: Push Docker Image - needs: build - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - job: - - { platform: "amd64", goos: "linux", docker_platform: "linux/amd64" } - - { platform: "arm64", goos: "linux", docker_platform: "linux/arm64" } - - { platform: "armv7l", goos: "linux", docker_platform: "linux/arm/v7" } - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Log in to Docker Hub - if: ${{ env.SKIP_DOCKER_HUB == 'false' }} # Only log in if SKIP_DOCKER_HUB is false - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_ACCESS_TOKEN }} - - - name: Log in to GitHub Container Registry - if: ${{ env.SKIP_GHCR == 'false' }} # Only log in if GHCR push is enabled - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract version from tag - id: vars - run: | - if [[ "${GITHUB_REF}" == refs/tags/* ]]; then - echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV - else - echo "TAG=latest" >> $GITHUB_ENV # Default to 'latest' if not a tag - fi - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v4 - with: - images: ${{ env.BASE_IMAGE_NAMESPACE }}/rustdesk-api - - - name: Download binaries - uses: actions/download-artifact@v4 - with: - name: rustdesk-api-${{ matrix.job.goos }}-${{ matrix.job.platform }} - path: ./ - - - name: Unzip binaries - run: | - mkdir -p ${{ matrix.job.platform }} - tar -xzf ${{ matrix.job.goos }}-${{ matrix.job.platform }}.tar.gz -C ${{ matrix.job.platform }} - - - name: Build and push Docker image to Docker Hub ${{ matrix.job.platform }} - if: ${{ env.SKIP_DOCKER_HUB == 'false' }} # Only run this step if SKIP_DOCKER_HUB is false - uses: docker/build-push-action@v5 - with: - context: "." - file: ./Dockerfile - platforms: ${{ matrix.job.docker_platform }} - push: true - provenance: false - build-args: | - BUILDARCH=${{ matrix.job.platform }} - tags: | - ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.LATEST_TAG }}-${{ matrix.job.platform }}, - ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-${{ matrix.job.platform }} - labels: ${{ steps.meta.outputs.labels }} - - - name: Build and push Docker Full S6 image to Docker Hub ${{ matrix.job.platform }} - if: ${{ env.SKIP_DOCKER_HUB == 'false' }} # Only run this step if SKIP_DOCKER_HUB is false - uses: docker/build-push-action@v5 - with: - context: "." - file: ./Dockerfile_full_s6 - platforms: ${{ matrix.job.docker_platform }} - push: true - provenance: false - build-args: | - BUILDARCH=${{ matrix.job.platform }} - tags: | - ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:full-s6-${{ matrix.job.platform }} - labels: ${{ steps.meta.outputs.labels }} - - - name: Build and push Docker image to GHCR ${{ matrix.job.platform }} - if: ${{ env.SKIP_GHCR == 'false' }} # Only run this step if SKIP_GHCR is false - uses: docker/build-push-action@v5 - with: - context: "." - file: ./Dockerfile - platforms: ${{ matrix.job.docker_platform }} - push: true - provenance: false - build-args: | - BUILDARCH=${{ matrix.job.platform }} - tags: | - ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.LATEST_TAG }}-${{ matrix.job.platform }}, - ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-${{ matrix.job.platform }} - labels: ${{ steps.meta.outputs.labels }} - - - name: Build and push Docker Full S6 image to GHCR ${{ matrix.job.platform }} - if: ${{ env.SKIP_GHCR == 'false' }} # Only run this step if SKIP_GHCR is false - uses: docker/build-push-action@v5 - with: - context: "." - file: ./Dockerfile - platforms: ${{ matrix.job.docker_platform }} - push: true - provenance: false - build-args: | - BUILDARCH=${{ matrix.job.platform }} - tags: | - ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:full-s6-${{ matrix.job.platform }} - labels: ${{ steps.meta.outputs.labels }} - - # - docker-manifest: - name: Push Docker Manifest - needs: docker - runs-on: ubuntu-latest - steps: - - name: Extract version from tag - id: vars - run: | - if [[ "${GITHUB_REF}" == refs/tags/* ]]; then - echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV - else - echo "TAG=latest" >> $GITHUB_ENV # Default to 'latest' if not a tag - fi - - - name: Log in to Docker Hub - if: ${{ env.SKIP_DOCKER_HUB == 'false' }} # Only log in if Docker Hub push is enabled - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_ACCESS_TOKEN }} - - - name: Log in to GitHub Container Registry - if: ${{ env.SKIP_GHCR == 'false' }} # Only log in if GHCR push is enabled - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Create and push manifest Docker Hub (:version) - if: ${{ env.SKIP_DOCKER_HUB == 'false' }} - uses: Noelware/docker-manifest-action@v0.2.3 - with: - base-image: ${{ env.BASE_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }} - extra-images: ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-amd64, - ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-armv7l, - ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-arm64 - push: true - - - name: Create and push manifest GHCR (:version) - if: ${{ env.SKIP_GHCR == 'false' }} - uses: Noelware/docker-manifest-action@v0.2.3 - with: - base-image: ghcr.io/${{ env.BASE_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }} - extra-images: ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-amd64, - ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-armv7l, - ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-arm64 - push: true - amend: true - - - name: Create and push manifest Docker Hub (:latest) - if: ${{ env.SKIP_DOCKER_HUB == 'false' }} - uses: Noelware/docker-manifest-action@v0.2.3 - with: - base-image: ${{ env.BASE_IMAGE_NAMESPACE }}/rustdesk-api:latest - extra-images: ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:latest-amd64, - ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:latest-armv7l, - ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:latest-arm64 - push: true - - - name: Create and push manifest GHCR (:latest) - if: ${{ env.SKIP_GHCR == 'false' }} - uses: Noelware/docker-manifest-action@v0.2.3 - with: - base-image: ghcr.io/${{ env.BASE_IMAGE_NAMESPACE }}/rustdesk-api:latest - extra-images: ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:latest-amd64, - ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:latest-armv7l, - ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:latest-arm64 - push: true - amend: true - - - name: Create and push Full S6 manifest Docker Hub (:version) - if: ${{ env.SKIP_DOCKER_HUB == 'false' }} - uses: Noelware/docker-manifest-action@v0.2.3 - with: - base-image: ${{ env.BASE_IMAGE_NAMESPACE }}/rustdesk-api:full-s6 - extra-images: ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:full-s6-amd64, - ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:full-s6-armv7l, - ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:full-s6-arm64 - push: true - amend: true - - - name: Create and push Full S6 manifest GHCR (:latest) - if: ${{ env.SKIP_GHCR == 'false' }} - uses: Noelware/docker-manifest-action@v0.2.3 - with: - base-image: ghcr.io/${{ env.BASE_IMAGE_NAMESPACE }}/rustdesk-api:full-s6 - extra-images: ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:full-s6-amd64, - ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:full-s6-armv7l, - ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:full-s6-arm64 - push: true - amend: true \ No newline at end of file diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml deleted file mode 100644 index 32bbf5f..0000000 --- a/.github/workflows/build_test.yml +++ /dev/null @@ -1,337 +0,0 @@ -name: Build Test - -on: - workflow_dispatch: - inputs: - BASE_IMAGE_NAMESPACE: - description: 'Base image namespace (Default: Your Github username)' - required: false - default: '' - DOCKERHUB_IMAGE_NAMESPACE: - description: 'Docker Hub image namespace (Default: Your Github username)' - required: false - default: '' - GHCR_IMAGE_NAMESPACE: - description: 'GitHub Container Registry image namespace (Default: Your Github username)' - required: false - default: '' - SKIP_DOCKER_HUB: - description: 'Set to true to skip pushing to Docker Hub (default: false)' - required: false - default: 'false' - SKIP_GHCR: - description: 'Set to true to skip pushing to GHCR (default: false)' - required: false - default: 'false' - WEBCLIENT_SOURCE_LOCATION: - description: 'Web Client API Repository' - required: true - default: 'https://github.com/lejianwen/rustdesk-api-web' - -env: - LATEST_TAG: latest - WEBCLIENT_SOURCE_LOCATION: ${{ github.event.inputs.WEBCLIENT_SOURCE_LOCATION || 'https://github.com/lejianwen/rustdesk-api-web' }} - BASE_IMAGE_NAMESPACE: ${{ github.event.inputs.BASE_IMAGE_NAMESPACE || github.actor }} - DOCKERHUB_IMAGE_NAMESPACE: ${{ github.event.inputs.DOCKERHUB_IMAGE_NAMESPACE || github.actor }} - GHCR_IMAGE_NAMESPACE: ${{ github.event.inputs.GHCR_IMAGE_NAMESPACE || github.actor }} - SKIP_DOCKER_HUB: ${{ github.event.inputs.SKIP_DOCKER_HUB || 'false' }} - SKIP_GHCR: ${{ github.event.inputs.SKIP_GHCR || 'false' }} -jobs: - build: - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - job: - - { platform: "amd64", goos: "linux", file_ext: "tar.gz" } - - { platform: "arm64", goos: "linux", file_ext: "tar.gz" } - - { platform: "armv7l", goos: "linux", file_ext: "tar.gz" } - - { platform: "amd64", goos: "windows", file_ext: "zip" } - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - uses: actions/checkout@v4 - with: - repository: lejianwen/rustdesk-api-web - path: rustdesk-api-web - ref: master - - - name: Set up Go environment - uses: actions/setup-go@v4 - with: - go-version: '1.23' # 选择 Go 版本 - - - name: Set up npm - uses: actions/setup-node@v2 - with: - node-version: '20' - - - name: build rustdesk-api-web - working-directory: rustdesk-api-web - run: | - npm install - npm run build - mkdir -p ../resources/admin/ - cp -ar dist/* ../resources/admin/ - - - name: tidy - run: go mod tidy - - - name: swag - run: | - go install github.com/swaggo/swag/cmd/swag@latest - swag init -g cmd/apimain.go --output docs/api --instanceName api --exclude http/controller/admin - swag init -g cmd/apimain.go --output docs/admin --instanceName admin --exclude http/controller/api - - - name: Build for ${{ matrix.job.goos }}-${{ matrix.job.platform }} - run: | - mkdir release -p - cp -ar resources release/ - cp -ar docs release/ - cp -ar conf release/ - mkdir -p release/data - mkdir -p release/runtime - if [ "${{ matrix.job.goos }}" = "windows" ]; then - sudo apt-get install gcc-mingw-w64-x86-64 zip -y - GOOS=${{ matrix.job.goos }} GOARCH=${{ matrix.job.platform }} CC=x86_64-w64-mingw32-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain.exe ./cmd/apimain.go - echo @echo off > release/start.bat - echo cmd /c \"%~dp0apimain.exe\" >> release/start.bat - zip -r ${{ matrix.job.goos}}-${{ matrix.job.platform }}.${{matrix.job.file_ext}} ./release - else - if [ "${{ matrix.job.platform }}" = "arm64" ]; then - wget https://musl.ljw.red/aarch64-linux-musl-cross.tgz - tar -xf aarch64-linux-musl-cross.tgz - export PATH=$PATH:$PWD/aarch64-linux-musl-cross/bin - GOOS=${{ matrix.job.goos }} GOARCH=${{ matrix.job.platform }} CC=aarch64-linux-musl-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain ./cmd/apimain.go - elif [ "${{ matrix.job.platform }}" = "armv7l" ]; then - wget https://musl.ljw.red/armv7l-linux-musleabihf-cross.tgz - tar -xf armv7l-linux-musleabihf-cross.tgz - export PATH=$PATH:$PWD/armv7l-linux-musleabihf-cross/bin - GOOS=${{ matrix.job.goos }} GOARCH=arm GOARM=7 CC=armv7l-linux-musleabihf-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain ./cmd/apimain.go - else - sudo apt-get install musl musl-dev musl-tools -y - GOOS=${{ matrix.job.goos }} GOARCH=${{ matrix.job.platform }} CC=musl-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain ./cmd/apimain.go - fi - tar -czf ${{ matrix.job.goos}}-${{ matrix.job.platform }}.${{matrix.job.file_ext}} ./release - fi - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: rustdesk-api-${{ matrix.job.goos }}-${{ matrix.job.platform }} - path: | - ${{ matrix.job.goos}}-${{ matrix.job.platform }}.${{matrix.job.file_ext}} - - - name: Upload to GitHub Release - uses: softprops/action-gh-release@v2 - with: - files: | - ${{ matrix.job.goos}}-${{ matrix.job.platform }}.${{matrix.job.file_ext}} - tag_name: test - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - deb-package: - name: debian package - ${{ matrix.job.platform }} - needs: build - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - job: - - { platform: "amd64", goos: "linux", debian_platform: "amd64", crossbuild_package: ""} - - { platform: "arm64", goos: "linux", debian_platform: "arm64", crossbuild_package: "crossbuild-essential-arm64" } - - { platform: "armv7l", goos: "linux", debian_platform: "armhf", crossbuild_package: "crossbuild-essential-armhf" } - steps: - - - name: Checkout - uses: actions/checkout@v3 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Create packaging env - run: | - sudo apt update - DEBIAN_FRONTEND=noninteractive sudo apt install -y devscripts build-essential debhelper pkg-config ${{ matrix.job.crossbuild_package }} - mkdir -p debian-build/${{ matrix.job.platform }}/bin - - - name: Download binaries - uses: actions/download-artifact@v4 - with: - name: rustdesk-api-${{ matrix.job.goos }}-${{ matrix.job.platform }} - path: . - - - name: Unzip binaries - run: | - mkdir -p ${{ matrix.job.platform }} - tar -xzf ${{ matrix.job.goos }}-${{ matrix.job.platform }}.tar.gz -C ${{ matrix.job.platform }} - - - name: Build package for ${{ matrix.job.platform }} arch - run: | - mv ${{ matrix.job.platform }}/release/apimain debian-build/${{ matrix.job.platform }}/bin/rustdesk-api - chmod -v a+x debian-build/${{ matrix.job.platform }}/bin/* - mkdir -p data - cp -vr debian systemd conf data resources runtime debian-build/${{ matrix.job.platform }}/ - cat debian/control.tpl | sed 's/{{ ARCH }}/${{ matrix.job.debian_platform }}/' > debian-build/${{ matrix.job.platform }}/debian/control - cd debian-build/${{ matrix.job.platform }}/ - debuild -i -us -uc -b -a${{ matrix.job.debian_platform}} - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: rustdesk-api-${{ matrix.job.debian_platform }} - path: | - debian-build/*.deb - - - name: Upload to GitHub Release - uses: softprops/action-gh-release@v2 - with: - tag_name: test - files: | - debian-build/rustdesk-api-server_*_${{ matrix.job.debian_platform }}.deb - - docker: - name: Push Docker Image - needs: build - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - job: - - { platform: "amd64", goos: "linux", docker_platform: "linux/amd64" } - - { platform: "arm64", goos: "linux", docker_platform: "linux/arm64" } - - { platform: "armv7l", goos: "linux", docker_platform: "linux/arm/v7" } - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Log in to Docker Hub - if: ${{ env.SKIP_DOCKER_HUB == 'false' }} # Only log in if SKIP_DOCKER_HUB is false - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_ACCESS_TOKEN }} - - - name: Log in to GitHub Container Registry - if: ${{ env.SKIP_GHCR == 'false' }} # Only log in if GHCR push is enabled - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract version from tag - id: vars - run: | - if [[ "${GITHUB_REF}" == refs/tags/* ]]; then - echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV - else - echo "TAG=test" >> $GITHUB_ENV # Default to 'test' if not a tag - fi - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v4 - with: - images: ${{ env.BASE_IMAGE_NAMESPACE }}/rustdesk-api - - - name: Download binaries - uses: actions/download-artifact@v4 - with: - name: rustdesk-api-${{ matrix.job.goos }}-${{ matrix.job.platform }} - path: ./ - - - name: Unzip binaries - run: | - mkdir -p ${{ matrix.job.platform }} - tar -xzf ${{ matrix.job.goos }}-${{ matrix.job.platform }}.tar.gz -C ${{ matrix.job.platform }} - - - name: Build and push Docker image to Docker Hub ${{ matrix.job.platform }} - if: ${{ env.SKIP_DOCKER_HUB == 'false' }} # Only run this step if SKIP_DOCKER_HUB is false - uses: docker/build-push-action@v5 - with: - context: "." - file: ./Dockerfile - platforms: ${{ matrix.job.docker_platform }} - push: true - provenance: false - build-args: | - BUILDARCH=${{ matrix.job.platform }} - tags: | - ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-${{ matrix.job.platform }} - labels: ${{ steps.meta.outputs.labels }} - - - name: Build and push Docker image to GHCR ${{ matrix.job.platform }} - if: ${{ env.SKIP_GHCR == 'false' }} # Only run this step if SKIP_GHCR is false - uses: docker/build-push-action@v5 - with: - context: "." - file: ./Dockerfile - platforms: ${{ matrix.job.docker_platform }} - push: true - provenance: false - build-args: | - BUILDARCH=${{ matrix.job.platform }} - tags: | - ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-${{ matrix.job.platform }} - labels: ${{ steps.meta.outputs.labels }} - - # - docker-manifest: - name: Push Docker Manifest - needs: docker - runs-on: ubuntu-latest - steps: - - name: Extract version from tag - id: vars - run: | - if [[ "${GITHUB_REF}" == refs/tags/* ]]; then - echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV - else - echo "TAG=test" >> $GITHUB_ENV # Default to 'test' if not a tag - fi - - - name: Log in to Docker Hub - if: ${{ env.SKIP_DOCKER_HUB == 'false' }} # Only log in if Docker Hub push is enabled - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_ACCESS_TOKEN }} - - - name: Log in to GitHub Container Registry - if: ${{ env.SKIP_GHCR == 'false' }} # Only log in if GHCR push is enabled - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Create and push manifest Docker Hub (:version) - if: ${{ env.SKIP_DOCKER_HUB == 'false' }} - uses: Noelware/docker-manifest-action@v0.2.3 - with: - base-image: ${{ env.BASE_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }} - extra-images: ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-amd64, - ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-armv7l, - ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-arm64 - push: true - - - name: Create and push manifest GHCR (:version) - if: ${{ env.SKIP_GHCR == 'false' }} - uses: Noelware/docker-manifest-action@v0.2.3 - with: - base-image: ghcr.io/${{ env.BASE_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }} - extra-images: ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-amd64, - ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-armv7l, - ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-arm64 - push: true - amend: true diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml new file mode 100644 index 0000000..da692fe --- /dev/null +++ b/.github/workflows/ci-docker.yml @@ -0,0 +1,128 @@ +name: CI and Docker Build + +on: + push: + branches: + - main + - master + tags: + - 'v*' + pull_request: + branches: + - main + - master + +jobs: + frontend: + name: Frontend Build + runs-on: ubuntu + container: + image: node:22 + steps: + - name: Clone rustdesk-api-web + run: | + git clone --depth 1 -b master https://git.viaeon.com/admin/rustdesk-api-web.git /tmp/web + cd /tmp/web + npm install + npm run build + + backend: + name: Backend Build + runs-on: ubuntu + container: + image: golang:1.23 + steps: + - name: Checkout and build + run: | + cd /tmp + git clone --depth=1 https://admin:${{ secrets.TOKEN }}@git.viaeon.com/admin/rustdesk-api.git repo + cd repo + go env -w GOPROXY=https://goproxy.cn,direct + go mod tidy + go mod download + CGO_ENABLED=1 go build -v -o bin/apimain ./cmd/apimain.go + + docker: + name: Build and Push Docker Image + runs-on: ubuntu + needs: [frontend, backend] + if: github.event_name == 'push' + env: + RUNNER_TOOL_CACHE: /toolcache + + steps: + - name: Install Docker CLI + run: | + if ! command -v docker &> /dev/null; then + if command -v apk &> /dev/null; then + apk add --no-cache docker-cli + elif command -v apt-get &> /dev/null; then + apt-get update && apt-get install -y docker.io + else + curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-24.0.7.tgz | tar xz -C /tmp + mv /tmp/docker/docker /usr/local/bin/ + chmod +x /usr/local/bin/docker + fi + fi + docker --version + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Login to Gitea Container Registry + run: | + echo "${{ secrets.TOKEN }}" | docker login git.viaeon.com -u "${{ github.actor }}" --password-stdin 2>&1 + + - name: Build Docker image + run: | + echo "Building image..." + docker build \ + --label "org.opencontainers.image.source=https://git.viaeon.com/admin/rustdesk-api" \ + --label "org.opencontainers.image.revision=${{ github.sha }}" \ + -f Dockerfile.ci \ + -t git.viaeon.com/admin/rustdesk-api:${{ github.ref_name }} \ + -t git.viaeon.com/admin/rustdesk-api:latest . 2>&1 + + - name: Push Docker image + run: | + echo "Pushing ${{ github.ref_name }}..." + docker push git.viaeon.com/admin/rustdesk-api:${{ github.ref_name }} 2>&1 + echo "Pushing latest..." + docker push git.viaeon.com/admin/rustdesk-api:latest 2>&1 + + deploy: + name: Deploy to Remote Server + runs-on: ubuntu + needs: docker + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + env: + RUNNER_TOOL_CACHE: /toolcache + + steps: + - name: Install SSH Client + run: | + if command -v apk &> /dev/null; then + apk add --no-cache openssh-client sshpass + elif command -v apt-get &> /dev/null; then + apt-get update && apt-get install -y openssh-client sshpass + else + echo "Cannot install sshpass" + exit 1 + fi + ssh -V + + - name: Deploy via SSH + run: | + sshpass -p '${{ secrets.DEPLOY_PASSWORD }}' ssh -o StrictHostKeyChecking=no -p ${{ secrets.DEPLOY_PORT || '22' }} ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} << ENDSSH + set -e + cd "${{ secrets.DEPLOY_PATH }}" + echo "Current directory: \$(pwd)" + echo "Pulling latest image..." + docker pull git.viaeon.com/admin/rustdesk-api:latest + echo "Restarting containers..." + docker compose down || true + docker compose up -d + echo "Cleaning up old images..." + docker image prune -f + echo "Deployment completed!" + ENDSSH diff --git a/Dockerfile.ci b/Dockerfile.ci new file mode 100644 index 0000000..bb97227 --- /dev/null +++ b/Dockerfile.ci @@ -0,0 +1,59 @@ +# 从源码完整构建 rustdesk-api(后端 + 前端),供 CI 使用 +# docker build -f Dockerfile.ci -t git.viaeon.com/admin/rustdesk-api:latest . + +# 阶段1: 构建前端 rustdesk-api-web +FROM node:22-alpine AS frontend-builder + +ARG FRONTEND_GIT_REPO=https://git.viaeon.com/admin/rustdesk-api-web.git +ARG FRONTEND_GIT_BRANCH=master +ARG NPM_REGISTRY=https://registry.npmmirror.com + +WORKDIR /web +RUN apk add --no-cache git +RUN npm config set registry ${NPM_REGISTRY} +RUN git clone --depth 1 -b ${FRONTEND_GIT_BRANCH} ${FRONTEND_GIT_REPO} . +RUN npm install && npm run build + +# 阶段2: 构建后端 +FROM golang:1.23-alpine AS backend-builder + +ENV GOPROXY=https://goproxy.cn,direct +ENV CGO_ENABLED=1 +ENV GOOS=linux + +WORKDIR /app +RUN apk add --no-cache git gcc musl-dev + +COPY . . + +RUN go mod tidy && go mod download + +RUN go install github.com/swaggo/swag/cmd/swag@latest && \ + swag init -g cmd/apimain.go --output docs/api --instanceName api --exclude http/controller/admin && \ + swag init -g cmd/apimain.go --output docs/admin --instanceName admin --exclude http/controller/api + +RUN go build -ldflags "-s -w" -o /app/release/apimain ./cmd/apimain.go + +# 最终镜像 +FROM alpine:latest + +RUN apk add --no-cache tzdata + +WORKDIR /app + +# 拷贝后端产物 +COPY --from=backend-builder /app/release/apimain ./ +COPY --from=backend-builder /app/conf ./conf +COPY --from=backend-builder /app/docs ./docs +COPY --from=backend-builder /app/resources ./resources + +# 拷贝前端产物到管理后台静态资源目录 +COPY --from=frontend-builder /web/dist ./resources/admin + +RUN mkdir -p /app/data /app/runtime + +VOLUME /app/data + +EXPOSE 21114 + +CMD ["./apimain"] diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..36fdf68 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,16 @@ +services: + rustdesk-api: + image: git.viaeon.com/admin/rustdesk-api:latest + container_name: rustdesk-api + environment: + - TZ=Asia/Shanghai + - RUSTDESK_API_RUSTDESK_ID_SERVER=${RUSTDESK_API_RUSTDESK_ID_SERVER:-192.168.1.66:21116} + - RUSTDESK_API_RUSTDESK_RELAY_SERVER=${RUSTDESK_API_RUSTDESK_RELAY_SERVER:-192.168.1.66:21117} + - RUSTDESK_API_RUSTDESK_API_SERVER=${RUSTDESK_API_RUSTDESK_API_SERVER:-http://127.0.0.1:21114} + - RUSTDESK_API_RUSTDESK_KEY=${RUSTDESK_API_RUSTDESK_KEY:-123456789} + ports: + - 21114:21114 + volumes: + - ./data/rustdesk/api:/app/data # database + # - ./conf:/app/conf # config + restart: unless-stopped