Skip to content

Commit cca2921

Browse files
committed
chore(k8s): add cd via timoni+flux
1 parent b4cb7e4 commit cca2921

File tree

415 files changed

+102198
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

415 files changed

+102198
-0
lines changed

.github/workflows/master.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,8 @@ jobs:
130130
# run: make test-code-checkers
131131
# env:
132132
# MIX_ENV: test
133+
134+
build-package:
135+
uses: ./.github/workflows/package.yaml
136+
with:
137+
is-pr: false

.github/workflows/package.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Build package
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
is-pr:
7+
description: Whether it's a pr
8+
type: boolean
9+
required: true
10+
jobs:
11+
build-package:
12+
permissions:
13+
contents: read
14+
packages: write
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Setup Timoni
19+
uses: stefanprodan/timoni/actions/setup@main
20+
- name: Setup Flux
21+
uses: fluxcd/flux2/action@main
22+
23+
- name: Preapre tag
24+
if: ${{ inputs.is-pr }}
25+
run: |
26+
tag=$(echo ${{ github.head_ref }} | tr '/' '-')
27+
echo "tag=${tag}" >> "${GITHUB_ENV}"
28+
29+
- name: Prepare tag
30+
if: ${{ ! inputs.is-pr }}
31+
run: echo "tag=${{ github.ref_name }}" >> "${GITHUB_ENV}"
32+
33+
- name: Build bundle
34+
env:
35+
BUNDLE_PATH: k8s/timoni/
36+
run: |
37+
mkdir ${{ runner.temp }}/timoni
38+
timoni bundle build \
39+
-f ${BUNDLE_PATH}bundle.cue \
40+
-f ${BUNDLE_PATH}runners.cue \
41+
-f ${BUNDLE_PATH}values.cue > ${{ runner.temp }}/timoni/build.yaml
42+
43+
- name: Diff artifacts
44+
run: |
45+
set +e
46+
flux diff artifact \
47+
--creds ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} \
48+
oci://ghcr.io/${{ github.repository }}-manifests:${tag} \
49+
--path ${{ runner.temp }}/timoni
50+
echo "diff=$?" >> "${GITHUB_ENV}"
51+
52+
- name: Push artifact
53+
if: ${{ env.diff != '0' }}
54+
run: |
55+
flux push artifact \
56+
--creds ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} \
57+
-f ${{ runner.temp }}/timoni \
58+
--source ${{ github.repositoryUrl }} \
59+
--revision ${{ inputs.tag }}@sha1:${{ github.sha }} \
60+
oci://ghcr.io/${{ github.repository }}-manifests:${tag}

.github/workflows/pr.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,8 @@ jobs:
9696
token: ${{ secrets.CODECOV_TOKEN }}
9797
file: ./services/app/assp/codebattle/cover/excoveralls.json
9898
fail_ci_if_error: false
99+
100+
build-package:
101+
uses: ./.github/workflows/package.yaml
102+
with:
103+
is-pr: true

k8s/flux.cue

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
bundle: {
2+
apiVersion: "v1alpha1"
3+
name: "codebattle"
4+
instances: {
5+
"codebattle": {
6+
module: url: "file://timoni/kustomize-oci"
7+
namespace: "flux-system"
8+
values: {
9+
artifact: {
10+
url: "oci://ghcr.io/hexlet-codebattle/codebattle-manifests"
11+
tag: "master"
12+
}
13+
auth: credentials: {
14+
username: string @timoni(runtime:string:GITHUB_USERNAME)
15+
password: string @timoni(runtime:string:GITHUB_TOKEN)
16+
}
17+
patches: [{
18+
apiVersion: "gateway.networking.k8s.io/v1"
19+
kind: "HTTPRoute"
20+
spec: {
21+
_hostname: string @timoni(runtime:string:CODEBATTLE_HOSTNAME)
22+
hostnames: [_hostname]
23+
}
24+
}]
25+
}
26+
}
27+
"gateway": {
28+
module: url: "oci://ghcr.io/stefanprodan/modules/flux-helm-release"
29+
namespace: "flux-system"
30+
values: {
31+
repository: url: "oci://registry-1.docker.io/envoyproxy"
32+
chart: {
33+
name: "gateway-helm"
34+
version: "v1.3.0"
35+
}
36+
}
37+
}
38+
}
39+
}

k8s/timoni/bundle.cue

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#RunnerConfig: {
2+
image: string
3+
version: string
4+
lang: string
5+
replicas: uint
6+
}
7+
8+
runners: [string]: #RunnerConfig
9+
codebattleValues: {}
10+
11+
bundle: {
12+
apiVersion: "v1alpha1"
13+
name: "codebattle"
14+
instances: {
15+
codebattle: {
16+
module: url: "file://codebattle"
17+
namespace: "codebattle"
18+
values: codebattleValues
19+
}
20+
for runner in runners {
21+
"runner-\(runner.lang)": {
22+
module: url: "file://runner"
23+
namespace: "codebattle"
24+
values: {
25+
registry: "docker.io"
26+
image: {
27+
repository: "\(registry)/\(runner.image)"
28+
tag: runner.version
29+
}
30+
replicas: runner.replicas
31+
}
32+
}
33+
}
34+
gateway: {
35+
module: url: "file://gateway"
36+
namespace: "codebattle"
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)