Skip to content

Commit bed96ed

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

File tree

214 files changed

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

214 files changed

+37474
-0
lines changed

.github/workflows/master.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,32 @@ jobs:
130130
# run: make test-code-checkers
131131
# env:
132132
# MIX_ENV: test
133+
134+
timoni-arftefact:
135+
permissions:
136+
contents: read
137+
packages: write
138+
runs-on: ubuntu-latest
139+
steps:
140+
- uses: actions/checkout@v4
141+
- name: Setup Timoni
142+
uses: stefanprodan/timoni/actions/setup@main
143+
- name: Setup Flux
144+
uses: fluxcd/flux2/action@main
145+
- name: Build bundle
146+
env:
147+
BUNDLE_PATH: k8s/timoni/
148+
run: |
149+
mkdir ${{ runner.temp }}/timoni
150+
timoni bundle build \
151+
-f ${BUNDLE_PATH}bundle.cue \
152+
-f ${BUNDLE_PATH}runners.cue \
153+
-f ${BUNDLE_PATH}values.cue > ${{ runner.temp }}/timoni/build.yaml
154+
- name: Push artifact
155+
run: |
156+
flux push artifact \
157+
--creds ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} \
158+
-f ${{ runner.temp }}/build \
159+
--source ${{ github.repositoryUrl }} \
160+
--revision ${{ github.ref_name }} \
161+
oci://ghcr.io/${{ github.repository }}:${{ github.ref_name }}

.github/workflows/pr.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,32 @@ jobs:
9696
token: ${{ secrets.CODECOV_TOKEN }}
9797
file: ./services/app/assp/codebattle/cover/excoveralls.json
9898
fail_ci_if_error: false
99+
100+
timoni-arftefact:
101+
permissions:
102+
contents: read
103+
packages: write
104+
runs-on: ubuntu-latest
105+
steps:
106+
- uses: actions/checkout@v4
107+
- name: Setup Timoni
108+
uses: stefanprodan/timoni/actions/setup@main
109+
- name: Setup Flux
110+
uses: fluxcd/flux2/action@main
111+
- name: Build bundle
112+
env:
113+
BUNDLE_PATH: k8s/timoni/
114+
run: |
115+
mkdir ${{ runner.temp }}/timoni
116+
timoni bundle build \
117+
-f ${BUNDLE_PATH}bundle.cue \
118+
-f ${BUNDLE_PATH}runners.cue \
119+
-f ${BUNDLE_PATH}values.cue > ${{ runner.temp }}/timoni/build.yaml
120+
- name: Push artifact
121+
run: |
122+
flux push artifact \
123+
--creds ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} \
124+
-f ${{ runner.temp }}/build \
125+
--source ${{ github.repositoryUrl }} \
126+
--revision ${{ github.head_ref }} \
127+
oci://ghcr.io/${{ github.repository }}:${{ github.head_ref}}

k8s/flux.cue

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
bundle: {
2+
apiVersion: "v1alpha1"
3+
name: "codebattle-cd"
4+
instances: "codebattle-cd": {
5+
module: url: "oci://ghcr.io/stefanprodan/modules/flux-oci-sync"
6+
namespace: "flux-system"
7+
values: {
8+
artifact: {
9+
url: "oci://ghcr.io/hexlet-codebattle/codebattle"
10+
tag: "main"
11+
}
12+
auth: credentials: {
13+
username: ""
14+
password: string @timoni(runtime:string:FLUX_TOKEN)
15+
}
16+
}
17+
}
18+
19+
}

k8s/timoni/bundle.cue

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}
35+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Code generated by cue get go. DO NOT EDIT.
2+
3+
//cue:generate cue get go k8s.io/api/admission/v1
4+
5+
package v1
6+
7+
#GroupName: "admission.k8s.io"
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
// Code generated by cue get go. DO NOT EDIT.
2+
3+
//cue:generate cue get go k8s.io/api/admission/v1
4+
5+
package v1
6+
7+
import (
8+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
"k8s.io/apimachinery/pkg/types"
10+
authenticationv1 "k8s.io/api/authentication/v1"
11+
"k8s.io/apimachinery/pkg/runtime"
12+
)
13+
14+
// AdmissionReview describes an admission review request/response.
15+
#AdmissionReview: {
16+
metav1.#TypeMeta
17+
18+
// Request describes the attributes for the admission request.
19+
// +optional
20+
request?: null | #AdmissionRequest @go(Request,*AdmissionRequest) @protobuf(1,bytes,opt)
21+
22+
// Response describes the attributes for the admission response.
23+
// +optional
24+
response?: null | #AdmissionResponse @go(Response,*AdmissionResponse) @protobuf(2,bytes,opt)
25+
}
26+
27+
// AdmissionRequest describes the admission.Attributes for the admission request.
28+
#AdmissionRequest: {
29+
// UID is an identifier for the individual request/response. It allows us to distinguish instances of requests which are
30+
// otherwise identical (parallel requests, requests when earlier requests did not modify etc)
31+
// The UID is meant to track the round trip (request/response) between the KAS and the WebHook, not the user request.
32+
// It is suitable for correlating log entries between the webhook and apiserver, for either auditing or debugging.
33+
uid: types.#UID @go(UID) @protobuf(1,bytes,opt)
34+
35+
// Kind is the fully-qualified type of object being submitted (for example, v1.Pod or autoscaling.v1.Scale)
36+
kind: metav1.#GroupVersionKind @go(Kind) @protobuf(2,bytes,opt)
37+
38+
// Resource is the fully-qualified resource being requested (for example, v1.pods)
39+
resource: metav1.#GroupVersionResource @go(Resource) @protobuf(3,bytes,opt)
40+
41+
// SubResource is the subresource being requested, if any (for example, "status" or "scale")
42+
// +optional
43+
subResource?: string @go(SubResource) @protobuf(4,bytes,opt)
44+
45+
// RequestKind is the fully-qualified type of the original API request (for example, v1.Pod or autoscaling.v1.Scale).
46+
// If this is specified and differs from the value in "kind", an equivalent match and conversion was performed.
47+
//
48+
// For example, if deployments can be modified via apps/v1 and apps/v1beta1, and a webhook registered a rule of
49+
// `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]` and `matchPolicy: Equivalent`,
50+
// an API request to apps/v1beta1 deployments would be converted and sent to the webhook
51+
// with `kind: {group:"apps", version:"v1", kind:"Deployment"}` (matching the rule the webhook registered for),
52+
// and `requestKind: {group:"apps", version:"v1beta1", kind:"Deployment"}` (indicating the kind of the original API request).
53+
//
54+
// See documentation for the "matchPolicy" field in the webhook configuration type for more details.
55+
// +optional
56+
requestKind?: null | metav1.#GroupVersionKind @go(RequestKind,*metav1.GroupVersionKind) @protobuf(13,bytes,opt)
57+
58+
// RequestResource is the fully-qualified resource of the original API request (for example, v1.pods).
59+
// If this is specified and differs from the value in "resource", an equivalent match and conversion was performed.
60+
//
61+
// For example, if deployments can be modified via apps/v1 and apps/v1beta1, and a webhook registered a rule of
62+
// `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]` and `matchPolicy: Equivalent`,
63+
// an API request to apps/v1beta1 deployments would be converted and sent to the webhook
64+
// with `resource: {group:"apps", version:"v1", resource:"deployments"}` (matching the resource the webhook registered for),
65+
// and `requestResource: {group:"apps", version:"v1beta1", resource:"deployments"}` (indicating the resource of the original API request).
66+
//
67+
// See documentation for the "matchPolicy" field in the webhook configuration type.
68+
// +optional
69+
requestResource?: null | metav1.#GroupVersionResource @go(RequestResource,*metav1.GroupVersionResource) @protobuf(14,bytes,opt)
70+
71+
// RequestSubResource is the name of the subresource of the original API request, if any (for example, "status" or "scale")
72+
// If this is specified and differs from the value in "subResource", an equivalent match and conversion was performed.
73+
// See documentation for the "matchPolicy" field in the webhook configuration type.
74+
// +optional
75+
requestSubResource?: string @go(RequestSubResource) @protobuf(15,bytes,opt)
76+
77+
// Name is the name of the object as presented in the request. On a CREATE operation, the client may omit name and
78+
// rely on the server to generate the name. If that is the case, this field will contain an empty string.
79+
// +optional
80+
name?: string @go(Name) @protobuf(5,bytes,opt)
81+
82+
// Namespace is the namespace associated with the request (if any).
83+
// +optional
84+
namespace?: string @go(Namespace) @protobuf(6,bytes,opt)
85+
86+
// Operation is the operation being performed. This may be different than the operation
87+
// requested. e.g. a patch can result in either a CREATE or UPDATE Operation.
88+
operation: #Operation @go(Operation) @protobuf(7,bytes,opt)
89+
90+
// UserInfo is information about the requesting user
91+
userInfo: authenticationv1.#UserInfo @go(UserInfo) @protobuf(8,bytes,opt)
92+
93+
// Object is the object from the incoming request.
94+
// +optional
95+
object?: runtime.#RawExtension @go(Object) @protobuf(9,bytes,opt)
96+
97+
// OldObject is the existing object. Only populated for DELETE and UPDATE requests.
98+
// +optional
99+
oldObject?: runtime.#RawExtension @go(OldObject) @protobuf(10,bytes,opt)
100+
101+
// DryRun indicates that modifications will definitely not be persisted for this request.
102+
// Defaults to false.
103+
// +optional
104+
dryRun?: null | bool @go(DryRun,*bool) @protobuf(11,varint,opt)
105+
106+
// Options is the operation option structure of the operation being performed.
107+
// e.g. `meta.k8s.io/v1.DeleteOptions` or `meta.k8s.io/v1.CreateOptions`. This may be
108+
// different than the options the caller provided. e.g. for a patch request the performed
109+
// Operation might be a CREATE, in which case the Options will a
110+
// `meta.k8s.io/v1.CreateOptions` even though the caller provided `meta.k8s.io/v1.PatchOptions`.
111+
// +optional
112+
options?: runtime.#RawExtension @go(Options) @protobuf(12,bytes,opt)
113+
}
114+
115+
// AdmissionResponse describes an admission response.
116+
#AdmissionResponse: {
117+
// UID is an identifier for the individual request/response.
118+
// This must be copied over from the corresponding AdmissionRequest.
119+
uid: types.#UID @go(UID) @protobuf(1,bytes,opt)
120+
121+
// Allowed indicates whether or not the admission request was permitted.
122+
allowed: bool @go(Allowed) @protobuf(2,varint,opt)
123+
124+
// Result contains extra details into why an admission request was denied.
125+
// This field IS NOT consulted in any way if "Allowed" is "true".
126+
// +optional
127+
status?: null | metav1.#Status @go(Result,*metav1.Status) @protobuf(3,bytes,opt)
128+
129+
// The patch body. Currently we only support "JSONPatch" which implements RFC 6902.
130+
// +optional
131+
patch?: bytes @go(Patch,[]byte) @protobuf(4,bytes,opt)
132+
133+
// The type of Patch. Currently we only allow "JSONPatch".
134+
// +optional
135+
patchType?: null | #PatchType @go(PatchType,*PatchType) @protobuf(5,bytes,opt)
136+
137+
// AuditAnnotations is an unstructured key value map set by remote admission controller (e.g. error=image-blacklisted).
138+
// MutatingAdmissionWebhook and ValidatingAdmissionWebhook admission controller will prefix the keys with
139+
// admission webhook name (e.g. imagepolicy.example.com/error=image-blacklisted). AuditAnnotations will be provided by
140+
// the admission webhook to add additional context to the audit log for this request.
141+
// +optional
142+
auditAnnotations?: {[string]: string} @go(AuditAnnotations,map[string]string) @protobuf(6,bytes,opt)
143+
144+
// warnings is a list of warning messages to return to the requesting API client.
145+
// Warning messages describe a problem the client making the API request should correct or be aware of.
146+
// Limit warnings to 120 characters if possible.
147+
// Warnings over 256 characters and large numbers of warnings may be truncated.
148+
// +optional
149+
warnings?: [...string] @go(Warnings,[]string) @protobuf(7,bytes,rep)
150+
}
151+
152+
// PatchType is the type of patch being used to represent the mutated object
153+
#PatchType: string // #enumPatchType
154+
155+
#enumPatchType:
156+
#PatchTypeJSONPatch
157+
158+
#PatchTypeJSONPatch: #PatchType & "JSONPatch"
159+
160+
// Operation is the type of resource operation being checked for admission control
161+
#Operation: string // #enumOperation
162+
163+
#enumOperation:
164+
#Create |
165+
#Update |
166+
#Delete |
167+
#Connect
168+
169+
#Create: #Operation & "CREATE"
170+
#Update: #Operation & "UPDATE"
171+
#Delete: #Operation & "DELETE"
172+
#Connect: #Operation & "CONNECT"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Code generated by cue get go. DO NOT EDIT.
2+
3+
//cue:generate cue get go k8s.io/api/admissionregistration/v1
4+
5+
// Package v1 is the v1 version of the API.
6+
// AdmissionConfiguration and AdmissionPluginConfiguration are legacy static admission plugin configuration
7+
// MutatingWebhookConfiguration and ValidatingWebhookConfiguration are for the
8+
// new dynamic admission controller configuration.
9+
package v1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Code generated by cue get go. DO NOT EDIT.
2+
3+
//cue:generate cue get go k8s.io/api/admissionregistration/v1
4+
5+
package v1
6+
7+
#GroupName: "admissionregistration.k8s.io"

0 commit comments

Comments
 (0)