Skip to content

Commit 5860b4b

Browse files
committed
feat: server deployment images can be configured via env vars
- CI: moves github workflows to self hosted runner
1 parent be85951 commit 5860b4b

7 files changed

Lines changed: 65 additions & 46 deletions

File tree

.github/workflows/helm-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
release:
3838
# depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions
3939
# see: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
40-
runs-on: ubuntu-latest
40+
runs-on: [self-hosted, linux]
4141
steps:
4242
- name: Checkout
4343
uses: actions/checkout@v4
@@ -58,7 +58,7 @@ jobs:
5858
environment:
5959
name: github-pages
6060
url: ${{ steps.deployment.outputs.page_url }}
61-
runs-on: ubuntu-latest
61+
runs-on: ${{ inputs.runner }}
6262
needs: release
6363
steps:
6464
- name: Deploy to GitHub Pages

.github/workflows/release.yml

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ permissions:
2121
jobs:
2222
github-release:
2323
name: Create Github Release
24-
runs-on: ubuntu-latest
24+
runs-on: [self-hosted, linux, x64]
2525
outputs:
2626
version: ${{ steps.meta.outputs.version }}
27-
is_nightly: ${{ steps.meta.outputs.is_nightly }}
27+
ref_slug: ${{ steps.meta.outputs.ref_slug }}
28+
default_branch_slug: ${{ steps.meta.outputs.default_branch_slug }}
29+
30+
is_pre_release: ${{ steps.meta.outputs.is_pre_release }}
2831
steps:
2932
- name: Checkout
3033
uses: actions/checkout@v4
@@ -35,46 +38,37 @@ jobs:
3538
- uses: nxtcoder17/actions/metadata@main
3639
id: meta
3740

38-
- name: create nightly github release (if applicable)
39-
shell: bash
40-
if: ${{ steps.meta.outputs.is_nightly == 'true' }}
41-
env:
42-
GH_TOKEN: ${{ github.token }}
43-
version: ${{steps.meta.outputs.version}}
44-
run: |+
45-
echo "🔖 recreating release for nightly tag ${{ steps.meta.outputs.version }}"
46-
gh release delete ${{steps.meta.outputs.version}} -y --cleanup-tag -R ${{ github.repository }} || echo "cleaned up ${{steps.meta.outputs.version}} tag"
47-
gh release create "${{steps.meta.outputs.version}}" -R "${{ github.repository }}" --generate-notes --prerelease
41+
- name: create github release
42+
uses: nxtcoder17/actions/github-release-create@main
43+
with:
44+
name: ${{steps.meta.outputs.version}}
45+
github_token: ${{github.token}}
46+
pre_release: ${{ steps.meta.outputs.is_pre_release }}
4847

49-
- name: upload kubernetes CRDs to github release
48+
- name: create unified CRDs file
5049
shell: bash
51-
env:
52-
GH_TOKEN: ${{ github.token }}
53-
version: ${{steps.meta.outputs.version}}
5450
run: |+
5551
for file in $(ls config/crd/bases/); do
5652
cat config/crd/bases/$file >> crds.yml
5753
done
5854
59-
opts=("-R" "${{github.repository}}")
60-
if [ "${{ steps.meta.outputs.is_nightly }}" = "true" ]; then
61-
opts+=("--clobber")
62-
fi
63-
64-
gh release upload "${{ steps.meta.outputs.version }}" ${opts[@]} crds.yml
55+
- name: upload kubernetes CRDs to github release
56+
uses: nxtcoder17/actions/github-release-upload@main
57+
with:
58+
name: ${{steps.meta.outputs.version}}
59+
github_token: ${{github.token}}
60+
files: |+
61+
crds.yml
6562
66-
build-container-image:
63+
build-image:
6764
strategy:
6865
fail-fast: true
6966
matrix:
70-
arch:
71-
- amd64
72-
- arm64
7367
include:
7468
- arch: amd64
75-
runner: ubuntu-latest
69+
runs-on: [self-hosted, linux, x64]
7670
- arch: arm64
77-
runner: ubuntu-24.04-arm
71+
runs-on: [self-hosted, linux, ARM64]
7872

7973
runs-on: ${{ matrix.runner }}
8074
name: Build Container Image
@@ -96,24 +90,23 @@ jobs:
9690
- name: docker build and push
9791
env:
9892
image: "ghcr.io/${{ github.repository }}/controller:${{ needs.github-release.outputs.version }}-${{ matrix.arch }}"
99-
buildx_cache: "ghcr.io/${{ github.repository }}/controller:__docker__buildx__cache__${{ matrix.arch }}__${{needs.github-release.outputs.version}}"
93+
buildx_cache: "ghcr.io/${{ github.repository }}/controller:buildx-cache-${{needs.github-release.outputs.ref_slug}}-${{matrix.arch}}"
94+
buildx_cache_default: "ghcr.io/${{ github.repository }}/controller:buildx-cache-${{needs.github-release.outputs.default_branch_slug}}-${{matrix.arch}}"
10095
run: |+
10196
docker buildx build -t "$image" \
10297
--cache-to type=registry,ref="$buildx_cache",mode=max,compression=zstd,compression-level=13,force-compression=true \
10398
--cache-from type=registry,ref="$buildx_cache" \
99+
--cache-from type=registry,ref="$buildx_cache_default" \
104100
--output=type=image,compression=zstd,force-compression=true,compression-level=13,push=true \
105101
.
106102
107103
publish-multiarch-image:
108-
runs-on: ubuntu-latest
104+
runs-on: [self-hosted, linux]
109105
name: publish-multiarch-image
110106
needs:
111107
- github-release
112-
- build-container-image
108+
- build-image
113109
steps:
114-
- name: Checkout
115-
uses: actions/checkout@v4
116-
117110
- uses: nxtcoder17/actions/setup-docker@main
118111
with:
119112
docker_registry: "ghcr.io"
@@ -133,11 +126,11 @@ jobs:
133126
secrets: inherit
134127
needs:
135128
- github-release
136-
- build-container-image
129+
- build-image
137130
with:
138131
chart_version: ${{ needs.github-release.outputs.version }}
139132
chart_app_version: ${{ needs.github-release.outputs.version }}
140-
overwrite_release_assets: ${{ needs.github-release.outputs.is_nightly }}
133+
overwrite_release_assets: ${{ needs.github-release.outputs.is_pre_release }}
141134
charts: |+
142135
./helm-chart
143136
github_release: "${{ needs.github-release.outputs.version }}"

config/manager/kustomization.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ resources:
33
apiVersion: kustomize.config.k8s.io/v1beta1
44
kind: Kustomization
55
images:
6-
- name: controller
6+
- name: controller-image
77
newName: ghcr.io/kloudlite/wireguard/controller
88
newTag: master-nightly
9+
10+
replacements:
11+
- source:
12+
value: "SAMPLE"
13+
targets:
14+
- select:
15+
name: controller-manager
16+
kind: Deployment
17+
fieldPaths:
18+
- spec.template.spec.containers.[name=manager].env.[name=WG_SERVER_IMAGE].value

config/manager/manager.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,15 @@ spec:
6161
- args:
6262
- --leader-elect
6363
- --health-probe-bind-address=:8081
64-
image: controller:latest
64+
image: controller-image
6565
name: manager
66+
env:
67+
- name: WG_SERVER_IMAGE
68+
value: "ghcr.io/kloudlite/wireguard/images/wireguard:latest"
69+
70+
- name: SIMPLE_DNS_SERVER_IMAGE
71+
value: "ghcr.io/nxtcoder17/simple-dns:v1.0.0"
72+
6673
ports: []
6774
securityContext:
6875
allowPrivilegeEscalation: false

internal/controller/server_controller.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ import (
4646
type envVars struct {
4747
PodCIDR string `env:"POD_CIDR" default:"10.42.0.0/16"`
4848
SvcCIDR string `env:"SVC_CIDR" default:"10.43.0.0/16"`
49+
50+
WgServerImage string `env:"WG_SERVER_IMAGE" default:"ghcr.io/kloudlite/wireguard/images/wireguard:latest"`
51+
SimpleDNSServerImage string `env:"SIMPLE_DNS_SERVER_IMAGE" default:"ghcr.io/nxtcoder17/simple-dns:v1.0.0"`
4952
}
5053

5154
// ServerReconciler reconciles a Server object
@@ -253,13 +256,15 @@ func (r *ServerReconciler) createDeployment(check *reconciler.Check[*v1.Server],
253256
})
254257
}
255258

256-
b, err := templates.ParseBytes(r.templateServerDeploymentSpec, templates.ParamsServerDeploymentSpec{
259+
b, err := templates.ParseBytes(r.templateServerDeploymentSpec, templates.ServerDeploymentSpecParams{
257260
PodLabels: map[string]string{"app": obj.Name},
258261
Wg0Conf: string(wg0Config),
259262
WgDNSTemplateParams: templates.WgDNSTemplateParams{
260-
KubeDNSSvcIP: kubeDNSSvc.Spec.ClusterIP,
261-
DNSLocalhosts: obj.Spec.DNS.Localhosts,
263+
SimpleDNSServerImage: r.env.SimpleDNSServerImage,
264+
KubeDNSSvcIP: kubeDNSSvc.Spec.ClusterIP,
265+
DNSLocalhosts: obj.Spec.DNS.Localhosts,
262266
},
267+
WgServerImage: r.env.WgServerImage,
263268
WgProxyTemplateParams: proxyParams,
264269
})
265270
if err != nil {

internal/templates/server-deployment-spec.yml.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ spec:
1313

1414
containers:
1515
- name: wireguard
16-
image: ghcr.io/kloudlite/wireguard/images/wireguard:latest
16+
image: {{.WgServerImage}}
1717
imagePullPolicy: Always
1818
command:
1919
- sh
@@ -52,7 +52,7 @@ spec:
5252

5353
{{- with .WgDNSTemplateParams }}
5454
- name: dns
55-
image: ghcr.io/nxtcoder17/simple-dns:master-nightly
55+
image: {{.SimpleDNSServerImage}}
5656
imagePullPolicy: Always
5757
args:
5858
- --addr

internal/templates/types.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ type ParamsWgPeerConf struct {
2727
KeepAlive int32
2828
}
2929

30-
type ParamsServerDeploymentSpec struct {
30+
type ServerDeploymentSpecParams struct {
3131
PodLabels map[string]string
3232
Wg0Conf string
3333

34+
WgServerImage string
35+
3436
WgDNSTemplateParams
3537

3638
WgProxyTemplateParams
@@ -47,6 +49,8 @@ type WgServiceSpecParams struct {
4749
type WgDNSTemplateParams struct {
4850
KubeDNSSvcIP string
4951
DNSLocalhosts []string
52+
53+
SimpleDNSServerImage string
5054
}
5155

5256
type PortMapping struct {

0 commit comments

Comments
 (0)