Skip to content

Commit

Permalink
chore(k8s): add cd via timoni+flux
Browse files Browse the repository at this point in the history
  • Loading branch information
kjubybot committed Feb 16, 2025
1 parent b4cb7e4 commit 39030d2
Show file tree
Hide file tree
Showing 413 changed files with 102,186 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Build package

on:
push:

jobs:
build-package:
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Timoni
uses: stefanprodan/timoni/actions/setup@main
- name: Setup Flux
uses: fluxcd/flux2/action@main

- name: Prepare tag
run: echo "tag=${{ github.ref_name }}" >> "${GITHUB_ENV}"

- name: Build bundle
env:
BUNDLE_PATH: k8s/timoni/
run: |
mkdir ${{ runner.temp }}/timoni
timoni bundle build \
-f ${BUNDLE_PATH}bundle.cue \
-f ${BUNDLE_PATH}runners.cue \
-f ${BUNDLE_PATH}values.cue > ${{ runner.temp }}/timoni/build.yaml
- name: Diff artifacts
run: |
set +e
flux diff artifact \
--creds ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} \
oci://ghcr.io/${{ github.repository }}-manifests:${tag} \
--path ${{ runner.temp }}/timoni
echo "diff=$?" >> "${GITHUB_ENV}"
- name: Push artifact
if: ${{ env.diff != '0' }}
run: |
flux push artifact \
--creds ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} \
-f ${{ runner.temp }}/timoni \
--source ${{ github.repositoryUrl }} \
--revision ${{ inputs.tag }}@sha1:${{ github.sha }} \
oci://ghcr.io/${{ github.repository }}-manifests:${tag}
44 changes: 44 additions & 0 deletions k8s/flux.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
bundle: {
apiVersion: "v1alpha1"
name: "codebattle"
instances: {
"gateway": {
module: url: "oci://ghcr.io/stefanprodan/modules/flux-helm-release"
namespace: "flux-system"
values: {
repository: url: "oci://registry-1.docker.io/envoyproxy"
chart: {
name: "gateway-helm"
version: "v1.3.0"
}
sync: targetNamespace: "codebattle"
}
}
"codebattle": {
module: url: "file://timoni/kustomize-oci"
namespace: "flux-system"
values: {
artifact: {
url: "oci://ghcr.io/hexlet-codebattle/codebattle-manifests"
tag: "master" @timoni(runtime:string:CODEBATTLE_PKG_TAG)
}
auth: credentials: {
username: string @timoni(runtime:string:GITHUB_USERNAME)
password: string @timoni(runtime:string:GITHUB_TOKEN)
}
patches: [{
apiVersion: "gateway.networking.k8s.io/v1"
kind: "HTTPRoute"
metadata: {
name: "codebattle"
namespace: "codebattle"
}
spec: {
_hostname: string @timoni(runtime:string:CODEBATTLE_HOSTNAME)
hostnames: [_hostname]
}
}]
}
}
}
}
39 changes: 39 additions & 0 deletions k8s/timoni/bundle.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#RunnerConfig: {
image: string
version: string
lang: string
replicas: uint
}

runners: [string]: #RunnerConfig
codebattleValues: {}

bundle: {
apiVersion: "v1alpha1"
name: "codebattle"
instances: {
codebattle: {
module: url: "file://codebattle"
namespace: "codebattle"
values: codebattleValues
}
for runner in runners {
"runner-\(runner.lang)": {
module: url: "file://runner"
namespace: "codebattle"
values: {
registry: "docker.io"
image: {
repository: "\(registry)/\(runner.image)"
tag: runner.version
}
replicas: runner.replicas
}
}
}
gateway: {
module: url: "file://gateway"
namespace: "codebattle"
}
}
}
Loading

0 comments on commit 39030d2

Please sign in to comment.