This repository has been archived by the owner on Jul 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (135 loc) · 4.98 KB
/
api.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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