radicle-heartwood-lfs/.github/workflows/deploy.yml

73 lines
3.5 KiB
YAML

name: Deploy
on:
push:
branches:
- deploy/*
jobs:
build-and-push-images:
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to the container registry
uses: docker/login-action@v2
with:
registry: gcr.io
username: _json_key
password: ${{ secrets.GCR_JSON_KEY }}
- name: Checkout code
uses: actions/checkout@v3
- name: Build and push radicle-node
id: radicle-node
uses: docker/build-push-action@v4
with:
context: .
file: radicle-node/Dockerfile
push: true
tags: gcr.io/radicle-services/radicle-node:latest,gcr.io/radicle-services/radicle-node:${{ github.sha }}
cache-from: type=registry,ref=gcr.io/radicle-services/radicle-node:latest
cache-to: type=inline
- name: Build and push radicle-httpd
id: radicle-httpd
uses: docker/build-push-action@v4
with:
context: .
file: radicle-httpd/Dockerfile
push: true
tags: gcr.io/radicle-services/radicle-httpd:latest,gcr.io/radicle-services/radicle-httpd:${{ github.sha }}
cache-from: type=registry,ref=gcr.io/radicle-services/radicle-httpd:latest
cache-to: type=inline
deploy-seed-node:
runs-on: ubuntu-latest
needs: build-and-push-images
permissions:
contents: 'read'
id-token: 'write'
strategy:
matrix:
host: [seed]
include:
- host: seed
zone: europe-west4-c
steps:
- id: 'auth'
uses: 'google-github-actions/auth@v0'
with:
workload_identity_provider: 'projects/281042598092/locations/global/workloadIdentityPools/github-actions/providers/google-cloud'
service_account: 'github-actions@radicle-services.iam.gserviceaccount.com'
- name: Fetch host .env file
run: gcloud beta compute ssh --zone ${{ matrix.zone }} "github-actions@alt-clients-${{ matrix.host }}" --project "radicle-services" --command="curl https://raw.githubusercontent.com/${{ github.repository }}/${{ github.sha }}/.env.${{ matrix.host }} >.env"
- name: Fetch docker-compose.yml
run: gcloud beta compute ssh --zone ${{ matrix.zone }} "github-actions@alt-clients-${{ matrix.host }}" --project "radicle-services" --command="curl https://raw.githubusercontent.com/${{ github.repository }}/${{ github.sha }}/docker-compose.yml >docker-compose.yml"
- name: Make room for new images
run: gcloud beta compute ssh --zone ${{ matrix.zone }} "github-actions@alt-clients-${{ matrix.host }}" --project "radicle-services" --command="docker system prune --all --force"
- name: Pull container images
run: gcloud beta compute ssh --zone ${{ matrix.zone }} "github-actions@alt-clients-${{ matrix.host }}" --project "radicle-services" --command="RADICLE_IMAGE_TAG=${{ github.sha }} docker-compose --file docker-compose.yml pull"
- name: Stop services
run: gcloud beta compute ssh --zone ${{ matrix.zone }} "github-actions@alt-clients-${{ matrix.host }}" --project "radicle-services" --command="RADICLE_IMAGE_TAG=${{ github.sha }} docker-compose --file docker-compose.yml down"
- name: Restart services
run: gcloud beta compute ssh --zone ${{ matrix.zone }} "github-actions@alt-clients-${{ matrix.host }}" --project "radicle-services" --command="RADICLE_IMAGE_TAG=${{ github.sha }} docker-compose --file docker-compose.yml up --detach"