|
| 1 | +name: .NET service build & deploy |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + service_name: |
| 7 | + description: "Service name (used for GHCR image path: ghcr.io/midiantechnology/<service_name>)" |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + dokku_app_ams1: |
| 11 | + description: "Dokku app name on AMS1 host" |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + dokku_app_lon1: |
| 15 | + description: "Dokku app name on LON1 host" |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + dockerfile_path: |
| 19 | + description: "Path to the Dockerfile (default: Dockerfile at repo root)" |
| 20 | + required: false |
| 21 | + type: string |
| 22 | + default: "Dockerfile" |
| 23 | + secrets: |
| 24 | + DOKKU_AMS1_SSH_KEY: |
| 25 | + required: true |
| 26 | + DOKKU_LON1_SSH_KEY: |
| 27 | + required: true |
| 28 | + TS_OAUTH_CLIENT_ID: |
| 29 | + required: true |
| 30 | + TS_OAUTH_SECRET: |
| 31 | + required: true |
| 32 | + |
| 33 | +jobs: |
| 34 | + build-and-push: |
| 35 | + runs-on: ubuntu-latest |
| 36 | + permissions: |
| 37 | + contents: read |
| 38 | + packages: write |
| 39 | + steps: |
| 40 | + - name: Checkout service repo |
| 41 | + uses: actions/checkout@v4 |
| 42 | + |
| 43 | + - name: Set up Docker Buildx |
| 44 | + uses: docker/setup-buildx-action@v3 |
| 45 | + |
| 46 | + - name: Log in to GHCR |
| 47 | + uses: docker/login-action@v3 |
| 48 | + with: |
| 49 | + registry: ghcr.io |
| 50 | + username: ${{ github.actor }} |
| 51 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 52 | + |
| 53 | + - name: Build and push image |
| 54 | + uses: docker/build-push-action@v6 |
| 55 | + with: |
| 56 | + context: . |
| 57 | + file: ${{ inputs.dockerfile_path }} |
| 58 | + platforms: linux/amd64 |
| 59 | + push: true |
| 60 | + cache-from: type=gha |
| 61 | + cache-to: type=gha,mode=max |
| 62 | + tags: | |
| 63 | + ghcr.io/midiantechnology/${{ inputs.service_name }}:${{ github.sha }} |
| 64 | + ${{ github.ref == 'refs/heads/master' && format('ghcr.io/midiantechnology/{0}:master', inputs.service_name) || '' }} |
| 65 | +
|
| 66 | + deploy-ams1: |
| 67 | + needs: build-and-push |
| 68 | + runs-on: ubuntu-latest |
| 69 | + steps: |
| 70 | + - name: Join Tailscale |
| 71 | + uses: tailscale/github-action@v3 |
| 72 | + with: |
| 73 | + oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} |
| 74 | + oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} |
| 75 | + tags: tag:ci-runner |
| 76 | + |
| 77 | + - name: Configure SSH agent |
| 78 | + uses: webfactory/ssh-agent@v0.9.0 |
| 79 | + with: |
| 80 | + ssh-private-key: ${{ secrets.DOKKU_AMS1_SSH_KEY }} |
| 81 | + |
| 82 | + - name: Trust AMS1 host key |
| 83 | + run: | |
| 84 | + mkdir -p ~/.ssh |
| 85 | + ssh-keyscan -H -p 22 100.106.105.129 >> ~/.ssh/known_hosts |
| 86 | +
|
| 87 | + - name: Deploy to Dokku (AMS1) |
| 88 | + run: | |
| 89 | + ssh dokku@100.106.105.129 \ |
| 90 | + git:from-image ${{ inputs.dokku_app_ams1 }} \ |
| 91 | + ghcr.io/midiantechnology/${{ inputs.service_name }}:${{ github.sha }} |
| 92 | +
|
| 93 | + deploy-lon1: |
| 94 | + needs: build-and-push |
| 95 | + runs-on: ubuntu-latest |
| 96 | + steps: |
| 97 | + - name: Join Tailscale |
| 98 | + uses: tailscale/github-action@v3 |
| 99 | + with: |
| 100 | + oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} |
| 101 | + oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} |
| 102 | + tags: tag:ci-runner |
| 103 | + |
| 104 | + - name: Configure SSH agent |
| 105 | + uses: webfactory/ssh-agent@v0.9.0 |
| 106 | + with: |
| 107 | + ssh-private-key: ${{ secrets.DOKKU_LON1_SSH_KEY }} |
| 108 | + |
| 109 | + - name: Trust LON1 host key |
| 110 | + run: | |
| 111 | + mkdir -p ~/.ssh |
| 112 | + ssh-keyscan -H -p 22 100.103.110.99 >> ~/.ssh/known_hosts |
| 113 | +
|
| 114 | + - name: Deploy to Dokku (LON1) |
| 115 | + run: | |
| 116 | + ssh dokku@100.103.110.99 \ |
| 117 | + git:from-image ${{ inputs.dokku_app_lon1 }} \ |
| 118 | + ghcr.io/midiantechnology/${{ inputs.service_name }}:${{ github.sha }} |
0 commit comments