|
4 | 4 | push: |
5 | 5 | branches: |
6 | 6 | - "main" |
| 7 | + paths: |
| 8 | + - 'voxelbot/**' |
| 9 | + - 'ansible/**' |
| 10 | + - 'dockerfile' |
| 11 | + - 'docker-compose.yaml' |
| 12 | + - '.github/workflows/build-and-publish.yml' |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: "${{ github.ref_name }}-build-and-deploy" |
7 | 16 |
|
8 | 17 | jobs: |
9 | 18 | build: |
10 | 19 | runs-on: ubuntu-latest |
11 | 20 | permissions: |
12 | 21 | contents: 'write' |
13 | 22 | id-token: 'write' |
14 | | - env: |
15 | | - GCP_LOCATION: '' |
16 | | - GCP_PROJECT: '' |
17 | | - GCP_DOCKER_REPOSITORY: '' |
18 | | - GCP_HELM_REGISTRY: '' |
19 | | - GCP_SERVICE_ACCOUNT: '' |
20 | | - VERSION: ${{ github.sha }} |
| 23 | + |
21 | 24 | steps: |
22 | 25 | - uses: actions/checkout@v4 |
| 26 | + |
23 | 27 | - name: Authenticate to Google Cloud |
24 | 28 | uses: google-github-actions/auth@v2 |
25 | 29 | with: |
26 | | - project_id: ${{ env.GCP_PROJECT }} |
27 | | - service_account: ${{ env.GCP_SERVICE_ACCOUNT }} |
| 30 | + project_id: ${{ secrets.GCP_PROJECT }} |
| 31 | + service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} |
28 | 32 | workload_identity_provider: ${{ secrets.ORG_GOOGLE_WORKLOAD_IDP }} |
| 33 | + |
29 | 34 | - name: Set Up Cloud SDK |
30 | 35 | uses: google-github-actions/setup-gcloud@v2 |
| 36 | + with: |
| 37 | + install_components: 'beta' |
| 38 | + |
31 | 39 | - name: Docker login |
32 | 40 | run: | |
33 | 41 | gcloud auth print-access-token | docker login \ |
34 | 42 | -u oauth2accesstoken \ |
35 | | - --password-stdin "https://${{ env.GCP_LOCATION }}-docker.pkg.dev" |
36 | | - - name: Helm login |
37 | | - run: | |
38 | | - gcloud auth print-access-token | \ |
39 | | - helm registry login -u oauth2accesstoken \ |
40 | | - --password-stdin "https://${{ env.GCP_LOCATION }}-docker.pkg.dev" |
| 43 | + --password-stdin "https://${{ secrets.GCP_LOCATION }}-docker.pkg.dev" |
| 44 | +
|
41 | 45 | - name: Set up Docker Buildx |
42 | 46 | uses: docker/setup-buildx-action@v3 |
| 47 | + |
43 | 48 | - name: Build and push |
44 | 49 | uses: docker/build-push-action@v6 |
45 | 50 | with: |
46 | 51 | push: true |
47 | 52 | platforms: linux/amd64,linux/arm64 |
48 | | - file: ./external/VoxelBot/dockerfile |
49 | | - context: ./external/VoxelBot |
50 | | - tags: ${{ env.GCP_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT }}/${{ env.GCP_DOCKER_REPOSITORY }}/voxel51-discordbot:${{ env.VERSION }} |
| 53 | + file: dockerfile |
| 54 | + context: . |
| 55 | + tags: ${{ secrets.GCP_LOCATION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/${{ secrets.GCP_DOCKER_REPOSITORY }}/voxel51-discordbot:${{ github.sha }} |
| 56 | + cache-from: type=gha |
| 57 | + cache-to: type=gha,node=max |
| 58 | + |
| 59 | + - name: Deploy via ansible |
| 60 | + shell: bash |
| 61 | + env: |
| 62 | + DOCKER_REGISTRY: "${{ secrets.GCP_LOCATION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/${{ secrets.GCP_DOCKER_REPOSITORY }}/" |
| 63 | + GCP_SM_KEY: "${{ secrets.GCP_SM_KEY }}" |
| 64 | + TAG: ${{ github.sha }} |
| 65 | + GCP_COMPUTE_SERVER_NAME: "${{ secrets.GCP_COMPUTE_SERVER_NAME }}" |
| 66 | + GCP_LOCATION: ${{ secrets.GCP_LOCATION }} |
| 67 | + GCP_PROJECT: ${{ secrets.GCP_PROJECT }} |
| 68 | + run: | |
| 69 | + pushd ansible |
| 70 | + yq -i ".projects |= [\"$GCP_PROJECT\"]" ./inventory/gcp.yml |
| 71 | + yq -i ".zones |= [\"$GCP_LOCATION\"]" ./inventory/gcp.yml |
| 72 | + sudo pipx inject ansible-core -r requirements.txt |
| 73 | + ansible-playbook site.yml |
| 74 | + popd |
0 commit comments