Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

API Deployment

API Deployment #57

Workflow file for this run

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: self-hosted
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: Configure Docker
uses: docker/setup-buildx-action@v2
with:
version: latest
platforms: linux/amd64
- name: Login to iad.ocir.io
uses: docker/login-action@v2
with:
registry: iad.ocir.io
username: ${{ secrets.OCIR_USER }}
password: ${{ secrets.OCIR_TOKEN }}
- 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 iad.ocir.io/idydjmpmhphx/tale/cnstr-api:${{ env.git_version }}
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: iad.ocir.io/idydjmpmhphx/tale/cnstr-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/arm64
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