# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven # This workflow uses actions that are not certified by GitHub. # They are provided by a third-party and are governed by # separate terms of service, privacy policy, and support # documentation. # # github:依次添加以下变量, # 路径:Settings -> Secrets And Variables -> Actions # Repository secrets -> New repository secret -> 输入变量名和值 # SERVER_HOST / Secret:服务器公网IP # SERVER_USERNAME / Secret:服务器用户名 # SERVER_PASSWORD / Secret:服务器密码 # SERVER_PORT / Secret:服务器端口 name: cicd on: push: branches: main # 打标签的时候触发 tags: - '*' jobs: build: # 取消自动构建, 只在开源库执行,私有库不执行,开源库设置为 true if: false runs-on: ubuntu-latest # 运行环境 steps: - name: checkout code uses: actions/checkout@v4 # https://github.com/actions/setup-java - name: install JDK17 uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' cache: maven # https://github.com/arduino/setup-protoc - name: Install Protoc uses: arduino/setup-protoc@v3 # 直接本地打包好jar包,然后上传到服务器? - name: Maven build run: | mvn clean mvn -B -DskipTests=true install --file pom.xml cd starter mvn -B -DskipTests=true package --file pom.xml # 提取 Git 标签 - name: Extract Git tag id: extract_tag run: echo "TAG=$(echo ${GITHUB_REF#refs/tags/})" >> $GITHUB_ENV # https://github.com/docker/login-action - name: login to docker hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} # https://github.com/docker/setup-buildx-action - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - name: Create and use a new builder run: | docker buildx create --use --name mybuilder docker buildx inspect mybuilder --bootstrap # 构建并推送 Docker 镜像到 Docker Hub # https://hub.docker.com/r/bytedesk/bytedesk - name: Build and push Docker image to Docker Hub uses: docker/build-push-action@v6 with: context: ./starter # 确保构建上下文路径正确 file: ./starter/Dockerfile # 确保 Dockerfile 文件路径正确 push: true tags: ${{ secrets.DOCKER_HUB_USERNAME }}/bytedesk-ce:latest # tags: ${{ secrets.DOCKER_HUB_USERNAME }}/bytedesk:${{ env.TAG }} # 自动设置为当前的 Git 标签 # https://hub.docker.com/_/eclipse-temurin # eclipse-temurin:17-jdk暂时不支持更多架构,暂时渠道:windows/arm64,macos/amd64,macos/arm64,windows/amd64 platforms: linux/amd64,linux/arm64 # 登录阿里云 Docker # https://registry.cn-hangzhou.aliyuncs.com/bytedesk/bytedesk:latest - name: login to aliyun docker run: echo ${{ secrets.ALIYUN_DOCKER_PASSWORD }} | docker login --username ${{ secrets.ALIYUN_DOCKER_USERNAME }} --password-stdin registry.cn-hangzhou.aliyuncs.com # 构建并推送 Docker 镜像到阿里云 - name: Build and push Docker image to Aliyun uses: docker/build-push-action@v6 with: context: ./starter # 确保构建上下文路径正确 file: ./starter/Dockerfile # 确保 Dockerfile 文件路径正确 push: true tags: registry.cn-hangzhou.aliyuncs.com/bytedesk/bytedesk-ce:latest # tags: ${{ secrets.DOCKER_HUB_USERNAME }}/bytedesk:${{ env.TAG }} # 自动设置为当前的 Git 标签 # https://hub.docker.com/_/eclipse-temurin # eclipse-temurin:17-jdk暂时不支持更多架构,暂时渠道:windows/arm64,macos/amd64,macos/arm64,windows/amd64 platforms: linux/amd64,linux/arm64