deploy to GCS instead of gh pages #79
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: push | |
on: | |
push: | |
branches: [ main ] | |
jobs: | |
unit-test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: 1.21 | |
- name: Test backend | |
run: cd formulagraphql && go test -v ./... | |
build-graphql: | |
needs: [ unit-test ] | |
runs-on: ubuntu-latest #run this workflow on ubuntu instance | |
permissions: #make sure we add permission to read and write packages | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 #checkouts your repo, so this workflow can access it | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and export | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./formulagraphql | |
tags: formulagraphql:latest | |
outputs: type=docker,dest=/tmp/formulagraphql.tar | |
- name: Upload artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: formulagraphql | |
path: /tmp/formulagraphql.tar | |
push-graphql-to-ghcr: | |
needs: [ build-graphql ] | |
runs-on: ubuntu-latest #run this workflow on ubuntu instance | |
permissions: #make sure we add permission to read the package | |
contents: read | |
steps: | |
- name: Log in to GHCR | |
env: | |
REGISTRY: ghcr.io #create env called REGISTRY | |
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 | |
with: | |
registry: ${{ env.REGISTRY }} #parse REGISTRY env value to here. Make sure it is correctly stating ghcr.io | |
username: ${{ github.actor }} #this will be our github account | |
password: ${{ secrets.CR_PAT }} #parse the value of repository secret called CR_PAT that we have created earlier | |
- name: Extract metadata (tags, labels) for Docker GHCR | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
id: meta | |
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} #create ghcr image format within as id called meta | |
- name: Download artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: formulagraphql | |
path: /tmp | |
- name: Push image | |
env: | |
IMAGE_NAME: ${{ github.repository }} | |
run: | | |
docker load --input /tmp/formulagraphql.tar | |
docker tag formulagraphql:latest ghcr.io/$IMAGE_NAME:latest | |
docker push ghcr.io/$IMAGE_NAME:latest | |
push-graphql-to-gcr: | |
needs: [ build-graphql ] | |
runs-on: ubuntu-latest #run this workflow on ubuntu instance | |
permissions: #make sure we add permission to read the package | |
contents: read | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: formulagraphql | |
path: /tmp | |
- name: Load image | |
run: | | |
docker load --input /tmp/formulagraphql.tar | |
- name: Login to GCR | |
env: | |
PROJECT_ID: f1graph | |
uses: google-github-actions/[email protected] #checkouts GCR repo, so this workflow can access it | |
with: | |
service_account_key: ${{ secrets.GOOGLE_CREDENTIALS }} #parse the value of repository secret called SERVICE_ACCOUNT_KEY that we have created earlier | |
project_id: ${{ env.PROJECT_ID }} #parse the value of env called PROJECT_ID | |
export_default_credentials: true | |
- name: Configure Docker Client | |
run: |- | |
gcloud auth configure-docker --quiet | |
- name: Push Docker Image to Container Registry GCR | |
env: | |
IMAGE_NAME: formulagraphql | |
PROJECT_ID: f1graph | |
#tag docker image to gcr image format then push to gcr | |
run: |- | |
docker tag $IMAGE_NAME:latest gcr.io/$PROJECT_ID/$IMAGE_NAME:latest | |
docker push gcr.io/$PROJECT_ID/$IMAGE_NAME:latest | |
deploy-graphql: | |
needs: [ push-graphql-to-gcr ] | |
runs-on: ubuntu-latest #run this workflow on ubuntu instance | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
outputs: | |
url: ${{ steps.deploy.outputs.url }} | |
steps: | |
- uses: 'actions/checkout@v3' | |
- name: Login to GCP | |
env: | |
PROJECT_ID: f1graph | |
uses: google-github-actions/[email protected] #checkouts GCR repo, so this workflow can access it | |
with: | |
service_account_key: ${{ secrets.GOOGLE_CREDENTIALS }} #parse the value of repository secret called SERVICE_ACCOUNT_KEY that we have created earlier | |
project_id: ${{ env.PROJECT_ID }} #parse the value of env called PROJECT_ID | |
export_default_credentials: true | |
- id: 'deploy' | |
uses: 'google-github-actions/deploy-cloudrun@v1' | |
env: | |
IMAGE_NAME: formulagraphql | |
PROJECT_ID: f1graph | |
with: | |
service: backend | |
image: gcr.io/f1graph/formulagraphql:latest | |
region: europe-west1 | |
# - name: 'Use output' | |
# run: 'curl "${{ steps.deploy.outputs.url }}"' | |
deploy-frontend: | |
runs-on: ubuntu-latest | |
needs: [ deploy-graphql ] | |
steps: | |
- uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
override: true | |
target: wasm32-unknown-unknown | |
- uses: cargo-bins/cargo-binstall@main | |
- uses: Swatinem/rust-cache@v1 | |
- name: Install CLI | |
run: cargo binstall --no-confirm dioxus-cli --locked --force | |
- uses: actions/checkout@v2 | |
- name: Build | |
env: | |
GQL_ADDR: ${{needs.deploy-graphql.outputs.url}} | |
run: cd web && dx build --release | |
- name: Login to GCP | |
env: | |
PROJECT_ID: f1graph | |
uses: google-github-actions/[email protected] #checkouts GCR repo, so this workflow can access it | |
with: | |
service_account_key: ${{ secrets.GOOGLE_CREDENTIALS }} #parse the value of repository secret called SERVICE_ACCOUNT_KEY that we have created earlier | |
project_id: ${{ env.PROJECT_ID }} #parse the value of env called PROJECT_ID | |
export_default_credentials: true | |
- name: deploy to gcs | |
run: gsutil -m rsync -d -c -r ./web/site gs://my-gcs-bucket |