Skip to content

Commit ff31aaf

Browse files
authored
Merge pull request #2062 from hexlet-codebattle/chore/timoni-flux-cd
chore(k8s): add cd via timoni+flux
2 parents 9ad16cf + 62d6d1c commit ff31aaf

File tree

413 files changed

+102188
-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

+102188
-0
lines changed

.github/workflows/package.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Build package
2+
3+
on:
4+
push:
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+
run: |
21+
tag=$(echo ${{ github.ref_name}} | tr '/' '-')
22+
echo "tag=${tag}" >> "${GITHUB_ENV}"
23+
24+
- name: Build bundle
25+
env:
26+
BUNDLE_PATH: k8s/timoni/
27+
run: |
28+
mkdir ${{ runner.temp }}/timoni
29+
timoni bundle build \
30+
-f ${BUNDLE_PATH}bundle.cue \
31+
-f ${BUNDLE_PATH}runners.cue \
32+
-f ${BUNDLE_PATH}values.cue > ${{ runner.temp }}/timoni/build.yaml
33+
34+
- name: Diff artifacts
35+
run: |
36+
set +e
37+
flux diff artifact \
38+
--creds ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} \
39+
oci://ghcr.io/${{ github.repository }}-manifests:${tag} \
40+
--path ${{ runner.temp }}/timoni
41+
echo "diff=$?" >> "${GITHUB_ENV}"
42+
43+
- name: Push artifact
44+
if: ${{ env.diff != '0' }}
45+
run: |
46+
flux push artifact \
47+
--creds ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} \
48+
-f ${{ runner.temp }}/timoni \
49+
--source ${{ github.repositoryUrl }} \
50+
--revision ${{ inputs.tag }}@sha1:${{ github.sha }} \
51+
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)