|
| 1 | +name: Docker Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "main" |
| 7 | + tags: |
| 8 | + - "v*.*.*" |
| 9 | + |
| 10 | +env: |
| 11 | + IMAGE_NAME: rss3/xchar |
| 12 | + REGION_ID: us-east-1 |
| 13 | + DEV_ACK_CLUSTER_ID: cd1d0ffc40b5242b39ddda1864e71e30d |
| 14 | + PROD_ACK_CLUSTER_ID: cfc647c22fd6848b5a602ad4d7470632b |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + outputs: |
| 20 | + version: ${{ steps.meta.outputs.version }} |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v2 |
| 24 | + - name: docker meta |
| 25 | + id: meta |
| 26 | + uses: docker/metadata-action@v3 |
| 27 | + with: |
| 28 | + images: ${{ env.IMAGE_NAME }} |
| 29 | + tags: | |
| 30 | + type=sha |
| 31 | + - name: Set up Docker Buildx |
| 32 | + uses: docker/setup-buildx-action@v1 |
| 33 | + - name: Login to DockerHub |
| 34 | + if: github.event_name != 'pull_request' |
| 35 | + uses: docker/login-action@v1 |
| 36 | + with: |
| 37 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 38 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 39 | + - name: Build and push |
| 40 | + uses: docker/build-push-action@v2 |
| 41 | + with: |
| 42 | + context: . |
| 43 | + file: Dockerfile |
| 44 | + push: ${{ github.event_name != 'pull_request' }} |
| 45 | + tags: ${{ steps.meta.outputs.tags }} |
| 46 | + labels: ${{ steps.meta.outputs.labels }} |
| 47 | + |
| 48 | + deploy-dev: |
| 49 | + runs-on: ubuntu-latest |
| 50 | + needs: [build] |
| 51 | + steps: |
| 52 | + - name: Checkout |
| 53 | + uses: actions/checkout@v2 |
| 54 | + - name: Set K8s context |
| 55 | + uses: aliyun/ack-set-context@v1 |
| 56 | + with: |
| 57 | + access-key-id: "${{ secrets.ACCESS_KEY_ID }}" |
| 58 | + access-key-secret: "${{ secrets.ACCESS_KEY_SECRET }}" |
| 59 | + cluster-id: "${{ env.DEV_ACK_CLUSTER_ID }}" |
| 60 | + - name: Install Tools |
| 61 | + run: | |
| 62 | + wget https://github.com/mikefarah/yq/releases/download/v4.25.1/yq_linux_amd64.tar.gz -O - | tar xz && mv yq_linux_amd64 /usr/local/bin/yq |
| 63 | + curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.22.10/bin/linux/amd64/kubectl && chmod +x kubectl && mv kubectl /usr/local/bin/kubectl |
| 64 | + - uses: sljeff/secrets2env@main |
| 65 | + with: |
| 66 | + secrets-json: ${{ toJson(secrets) }} |
| 67 | + - env: |
| 68 | + IMAGE_TAG_RELEASE: ${{ env.IMAGE_NAME }}:${{ needs.build.outputs.version }} |
| 69 | + run: | |
| 70 | + sh apply.sh deploy/dev/* |
| 71 | +
|
| 72 | + deploy-prod: |
| 73 | + if: startsWith(github.ref, 'refs/tags/v') |
| 74 | + runs-on: ubuntu-latest |
| 75 | + needs: [build, deploy-dev] |
| 76 | + steps: |
| 77 | + - name: Checkout |
| 78 | + uses: actions/checkout@v2 |
| 79 | + - name: Set K8s context |
| 80 | + uses: aliyun/ack-set-context@v1 |
| 81 | + with: |
| 82 | + access-key-id: "${{ secrets.ACCESS_KEY_ID }}" |
| 83 | + access-key-secret: "${{ secrets.ACCESS_KEY_SECRET }}" |
| 84 | + cluster-id: "${{ env.PROD_ACK_CLUSTER_ID }}" |
| 85 | + - name: Install Tools |
| 86 | + run: | |
| 87 | + wget https://github.com/mikefarah/yq/releases/download/v4.25.1/yq_linux_amd64.tar.gz -O - | tar xz && mv yq_linux_amd64 /usr/local/bin/yq |
| 88 | + curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.22.10/bin/linux/amd64/kubectl && chmod +x kubectl && mv kubectl /usr/local/bin/kubectl |
| 89 | + - uses: sljeff/secrets2env@main |
| 90 | + with: |
| 91 | + secrets-json: ${{ toJson(secrets) }} |
| 92 | + - env: |
| 93 | + IMAGE_TAG_RELEASE: ${{ env.IMAGE_NAME }}:${{ needs.build.outputs.version }} |
| 94 | + run: | |
| 95 | + sh apply.sh deploy/prod/* |
0 commit comments