Skip to content

Deploy server

Deploy server #307

Workflow file for this run

name: Deploy server
on:
workflow_dispatch: {}
env:
CARGO_TERM_COLOR: always
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
BUILD_DIR: build-${{ github.sha }}
SERVER_BINARY_NAME: ambient-${{ github.sha }}
CANARY_SERVER_BINARY_NAME: ambient-0.3.2-dev
jobs:
build-and-push:
runs-on: ubuntu-22.04
permissions:
contents: read
id-token: write
packages: write
steps:
- uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=schedule
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
type=sha,format=long
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
file: Dockerfile
context: .
push: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# from some reason `docker create` doesn't like uppercase letters in image name
- name: Extract ambient server binary
run: |
raw_image_name="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:sha-${{ github.sha }}"
container_id=$(docker create "${raw_image_name,,}")
mkdir -p "${{ env.BUILD_DIR }}"
docker cp "$container_id:/app/ambient" "${{ env.BUILD_DIR }}/${{ env.SERVER_BINARY_NAME }}"
docker rm "$container_id"
- name: Authenticate with Google Cloud
id: auth
uses: google-github-actions/auth@v0
with:
token_format: access_token
workload_identity_provider: projects/549180905870/locations/global/workloadIdentityPools/github-pool/providers/github-provider
service_account: github@ambient-733e7.iam.gserviceaccount.com
access_token_lifetime: 1800s
- name: Prepare canary
if: github.ref == 'refs/heads/main'
shell: bash
run: cp "${{ env.BUILD_DIR }}/${{ env.SERVER_BINARY_NAME }}" "${{ env.BUILD_DIR }}/${{ env.CANARY_SERVER_BINARY_NAME }}"
- name: Prepare versioned
if: startsWith(github.ref, 'refs/tags/v')
shell: bash
run: cp "${{ env.BUILD_DIR }}/${{ env.SERVER_BINARY_NAME }}" "${{ env.BUILD_DIR }}/ambient-${GITHUB_REF#refs/tags/v}"
- name: Upload ambient server binary
uses: google-github-actions/upload-cloud-storage@v1
with:
path: ${{ env.BUILD_DIR }}
destination: ambient-artifacts/ambient-server-builds
parent: false