This repository has been archived by the owner on Jul 8, 2024. It is now read-only.
API Deployment #65
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: API Deployment | |
on: | |
workflow_dispatch: | |
inputs: | |
bump_type: | |
description: 'Version Bump Type' | |
required: true | |
default: 'patch' | |
type: choice | |
options: | |
- major | |
- minor | |
- patch | |
- release | |
- rc | |
- beta | |
- alpha | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
with: | |
repository: cnstr/api | |
ref: main | |
fetch-depth: 0 | |
token: ${{ secrets.PAT_TOKEN }} | |
- name: Configure Caching | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: cnstr-api-buildx-${{ github.sha }} | |
restore-keys: | | |
cnstr-api-buildx- | |
- name: Configure Rust and Cargo | |
uses: dtolnay/rust-toolchain@stable | |
- name: Setup QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Configure Docker | |
uses: docker/setup-buildx-action@v2 | |
with: | |
version: latest | |
platforms: linux/amd64 | |
- name: Login to gcr.io | |
uses: docker/login-action@v2 | |
with: | |
registry: us-east4-docker.pkg.dev | |
username: _json_key_base64 | |
password: ${{ secrets.SERVICE_ACCOUNT }} | |
- name: Load manifest.yaml for API | |
run: echo "$MANIFEST_BASE64" | base64 -d > manifest.yaml | |
env: | |
MANIFEST_BASE64: ${{ secrets.API_MANIFEST }} | |
- name: Update crate versions and set build-time variables | |
run: | | |
cargo install --force cargo-release | |
cargo release version --no-confirm -x -p api -p deploy $BUMP_TYPE | |
echo "git_version=$(cargo metadata --manifest-path crates/api/Cargo.toml --no-deps --format-version 1 | jq -r '.packages[0].version')" >> $GITHUB_ENV | |
echo "git_state=$(git rev-parse HEAD)" >> $GITHUB_ENV | |
echo "build_date=$(date --rfc-3339=date)" >> $GITHUB_ENV | |
env: | |
BUMP_TYPE: ${{ inputs.bump_type }} | |
- name: Build us-east4-docker.pkg.dev/aarnavtale/canister/api | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
tags: us-east4-docker.pkg.dev/aarnavtale/canister/api:${{ env.git_version }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-to,mode=max | |
platforms: linux/amd64 | |
build-args: | | |
BUILD_DATE=${{ env.build_date }} | |
VERSION=${{ env.git_version }} | |
GIT_STATE=${{ env.git_state }} | |
- name: Update Caching Layers | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-to /tmp/.buildx-cache | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
with: | |
repository: cnstr/api | |
ref: main | |
fetch-depth: 0 | |
token: ${{ secrets.PAT_TOKEN }} | |
- name: Configure Caching | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cargo/bin/ | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
target/ | |
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
- name: Configure Kubernetes | |
uses: tale/kubectl-action@v1 | |
with: | |
base64-kube-config: ${{ secrets.OCI_KUBE_CONFIG }} | |
kubectl-version: v1.28.2 | |
- name: Configure Rust and Cargo | |
uses: dtolnay/rust-toolchain@stable | |
- name: Load manifest.yaml for API | |
run: echo "$MANIFEST_BASE64" | base64 -d > manifest.yaml | |
env: | |
MANIFEST_BASE64: ${{ secrets.API_MANIFEST }} | |
- name: Install Rust dependencies and run deploy tool | |
run: | | |
cargo install --path crates/deploy | |
cargo install --force cargo-release | |
cargo release version --no-confirm -x -p api -p deploy $BUMP_TYPE | |
echo "git_version=$(cargo metadata --manifest-path crates/api/Cargo.toml --no-deps --format-version 1 | jq -r '.packages[0].version')" >> $GITHUB_ENV | |
cargo deploy | |
env: | |
BUMP_TYPE: ${{ inputs.bump_type }} | |
- name: Commit file changes | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: 'chore: update versions and manifests to ${{ env.git_version }}' | |
commit_author: 'github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>' | |
commit_options: '--no-verify --signoff' | |
file_pattern: 'Cargo.lock crates/api/Cargo.toml crates/deploy/Cargo.toml kubernetes/api.yaml' | |
- name: Create Git tags and deploy Kubernetes manifests | |
run: | | |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
cargo release tag --no-confirm -x -p api --tag-prefix "" | |
cargo release push --no-confirm -x -p api --tag-prefix "" | |
kubectl apply -f kubernetes/api.yaml |