Skip to content

Commit be2b229

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

File tree

413 files changed

+102193
-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.

413 files changed

+102193
-0
lines changed

.github/workflows/package.yaml

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

k8s/flux.cue

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

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)