diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml new file mode 100644 index 0000000..eae615c --- /dev/null +++ b/.github/workflows/develop.yml @@ -0,0 +1,75 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - develop + +env: + IMAGE_NAME: '' + REPO_NAME: '' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Setup Environments + shell: bash + run: | + IFS="/" read -r OWNER REPO <<< "$GITHUB_REPOSITORY" + echo "REPO_NAME=$REPO" >> $GITHUB_ENV + echo "IMAGE_NAME=${{ vars.REGISTRY_URL }}/${{ vars.REGISTRY_NAMESPACE }}/$REPO:$GITHUB_REF_NAME" >> $GITHUB_ENV + + - name: Checkout + uses: https://gitee.com/zuowenbo/checkout@v4.2.2 + + - name: Cache Docker layers + uses: https://gitee.com/zuowenbo/cache@v4.2.1 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ env.REPO_NAME }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-${{ env.REPO_NAME }}- + + - name: Set up Docker Buildx + uses: https://gitee.com/zuowenbo/setup-buildx-action@v3.9.0 + with: + driver-opts: image=registry.cn-shenzhen.aliyuncs.com/zuoge-proxy/buildkit:buildx-stable-1 + + - name: Login to Docker Hub + uses: https://gitee.com/zuowenbo/login-action@v3.3.0 + with: + registry: ${{ vars.REGISTRY_URL }} + username: ${{ vars.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Build and push final image + uses: https://gitee.com/zuowenbo/build-push-action@v6.14.0 + with: + context: . + tags: ${{ env.IMAGE_NAME }} + push: true + platforms: linux/amd64 + build-args: BRANCH=${{ env.GITHUB_REF_NAME }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max + + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache + + - name: Deploy to remote + uses: https://gitee.com/zuowenbo/ssh-action@v1.0.3 + with: + host: ${{ vars.DEV_HOST_IP }} + port: 22 + username: 'ubuntu' + password: ${{ secrets.DEV_HOST_PASSWORD }} + script: | + docker login -u ${{ vars.REGISTRY_USERNAME }} -p ${{ secrets.REGISTRY_PASSWORD }} ${{ vars.REGISTRY_URL}} + docker volume create ${{ env.REPO_NAME }} || true + docker pull ${{ env.IMAGE_NAME }} + docker stop ${{ env.REPO_NAME }} || true + docker rm ${{ env.REPO_NAME }} || true + docker run -d --restart always --network my_network --name ${{ env.REPO_NAME }} ${{ env.IMAGE_NAME }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..e89a8d8 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,75 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + +env: + IMAGE_NAME: '' + REPO_NAME: '' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Setup Environments + shell: bash + run: | + IFS="/" read -r OWNER REPO <<< "$GITHUB_REPOSITORY" + echo "REPO_NAME=$REPO" >> $GITHUB_ENV + echo "IMAGE_NAME=${{ vars.REGISTRY_URL }}/${{ vars.REGISTRY_NAMESPACE }}/$REPO:$GITHUB_REF_NAME" >> $GITHUB_ENV + + - name: Checkout + uses: https://gitee.com/zuowenbo/checkout@v4.2.2 + + - name: Cache Docker layers + uses: https://gitee.com/zuowenbo/cache@v4.2.1 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ env.REPO_NAME }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-${{ env.REPO_NAME }}- + + - name: Set up Docker Buildx + uses: https://gitee.com/zuowenbo/setup-buildx-action@v3.9.0 + with: + driver-opts: image=registry.cn-shenzhen.aliyuncs.com/zuoge-proxy/buildkit:buildx-stable-1 + + - name: Login to Docker Hub + uses: https://gitee.com/zuowenbo/login-action@v3.3.0 + with: + registry: ${{ vars.REGISTRY_URL }} + username: ${{ vars.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Build and push final image + uses: https://gitee.com/zuowenbo/build-push-action@v6.14.0 + with: + context: . + tags: ${{ env.IMAGE_NAME }} + push: true + platforms: linux/amd64 + build-args: BRANCH=${{ env.GITHUB_REF_NAME }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max + + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache + + - name: Deploy to remote + uses: https://gitee.com/zuowenbo/ssh-action@v1.0.3 + with: + host: ${{ vars.MAIN_HOST_IP }} + port: 22 + username: 'ubuntu' + password: ${{ secrets.MAIN_HOST_PASSWORD }} + script: | + docker login -u ${{ vars.REGISTRY_USERNAME }} -p ${{ secrets.REGISTRY_PASSWORD }} ${{ vars.REGISTRY_URL}} + docker volume create ${{ env.REPO_NAME }} || true + docker pull ${{ env.IMAGE_NAME }} + docker stop ${{ env.REPO_NAME }} || true + docker rm ${{ env.REPO_NAME }} || true + docker run -d --restart always --network my_network --name ${{ env.REPO_NAME }} ${{ env.IMAGE_NAME }} diff --git a/.gitignore b/.gitignore index ec0cabb..27a5b75 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ /dist /.mfsu .swc +/.idea \ No newline at end of file