Skip to content

Commit c7d2617

Browse files
authored
Merge pull request #6 from kloudlite/release-v1.0.1
Release v1.0.1
2 parents 8ecadef + 864f489 commit c7d2617

8 files changed

Lines changed: 225 additions & 26 deletions

File tree

.dockerignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
**
2-
!terraform/modules
3-
!terraform/bundles
2+
!terraform
43
!build-scripts
54
!infrastructure-templates
65
!.ci

.github/workflows/build-images.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: build-images
2+
3+
on:
4+
workflow_dispatch:
5+
6+
push:
7+
paths:
8+
- cmd/**
9+
- infrastructure-templates/**
10+
- terraform/**
11+
- ".github/workflows/**"
12+
- Dockerfile
13+
- .ci/**
14+
15+
permissions:
16+
contents: read
17+
packages: write
18+
19+
jobs:
20+
docker-builds:
21+
strategy:
22+
matrix:
23+
name:
24+
- infrastructure-as-code
25+
- aws-spot-k3s-terminator
26+
include:
27+
- name: infrastructure-as-code
28+
buildDir: .
29+
imageRepo: ghcr.io/${{ github.repository }}/iac-job
30+
31+
- name: aws-spot-k3s-terminator
32+
buildDir: cmd/aws-spot-k3s-terminator
33+
imageRepo: ghcr.io/${{ github.repository }}/aws-spot-k3s-terminator
34+
35+
runs-on: ubuntu-latest
36+
name: Deploy to Docker Image
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v3
40+
41+
- name: Set up QEMU
42+
uses: docker/setup-qemu-action@v2
43+
44+
- name: Set up Docker Buildx
45+
uses: docker/setup-buildx-action@v2
46+
47+
- name: Log in to the Container registry
48+
uses: docker/login-action@v3
49+
with:
50+
registry: ghcr.io
51+
username: ${{ github.actor }}
52+
password: ${{ secrets.GITHUB_TOKEN }}
53+
54+
- name: Create Image Tag from branch name
55+
if: startsWith(github.ref, 'refs/heads/release')
56+
run: |
57+
set +e
58+
IMAGE_TAG=$(echo ${GITHUB_REF#refs/heads/} | sed 's/release-//g')
59+
echo "$IMAGE_TAG" | grep -i '\-nightly$'
60+
if [ $? -ne 0 ]; then
61+
IMAGE_TAG="$IMAGE_TAG-nightly"
62+
fi
63+
set -e
64+
65+
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
66+
echo "OVERRIDE_PUSHED_IMAGE=true" >> $GITHUB_ENV
67+
68+
- name: Create Image Tag from tag
69+
if: startsWith(github.ref, 'refs/tags/')
70+
run: |
71+
IMAGE_TAG=$(echo ${GITHUB_REF#refs/tags/})
72+
73+
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
74+
echo "OVERRIDE_PUSHED_IMAGE=false" >> $GITHUB_ENV
75+
76+
- name: Build & Push Image
77+
if: startsWith(github.ref, 'refs/heads/release') || startsWith(github.ref, 'refs/tags/')
78+
run: |
79+
set +e
80+
pushd ${{matrix.buildDir}}
81+
82+
image=${{matrix.imageRepo}}:$IMAGE_TAG
83+
echo "building image: $image"
84+
85+
docker manifest inspect $image
86+
exit_status=$?
87+
if [ $exit_status -eq 0 ]; then
88+
[ "$OVERRIDE_PUSHED_IMAGE" = "false" ] && echo "image ($image) already exists, and override image is disable, exiting" && exit 0
89+
echo "image exists, but override pushed image is set to true. proceeding with building image"
90+
fi
91+
92+
set -e
93+
94+
docker buildx build -t $image . --push
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name:
2+
3+
on:
4+
workflow_dispatch:
5+
6+
push:
7+
paths:
8+
- cmd/k3s-runner
9+
- ".github/workflows/**"
10+
11+
permissions:
12+
contents: write
13+
id-token: write
14+
15+
jobs:
16+
docker-builds:
17+
strategy:
18+
matrix:
19+
target_arch:
20+
- amd64
21+
- arm64
22+
23+
runs-on: ubuntu-latest
24+
name: Deploy to Docker Image
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v3
28+
29+
- name: Install Go
30+
uses: actions/setup-go@v5
31+
with:
32+
go-version: 1.21.5
33+
34+
- name: Install Task
35+
uses: arduino/setup-task@v1
36+
with:
37+
version: 3.x
38+
repo-token: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Install UPX
41+
run: |
42+
curl -L0 https://github.com/upx/upx/releases/download/v4.2.1/upx-4.2.1-amd64_linux.tar.xz > upx.tar.xz
43+
tar -xf upx.tar.xz
44+
sudo mv upx-4.2.1-amd64_linux/upx /usr/local/bin
45+
46+
47+
- name: Create Release Tag from branch name
48+
if: startsWith(github.ref, 'refs/heads/release')
49+
run: |
50+
set +e
51+
RELEASE_TAG=$(echo ${GITHUB_REF#refs/heads/} | sed 's/release-//g')
52+
echo "$RELEASE_TAG" | grep -i '\-nightly$'
53+
if [ $? -ne 0 ]; then
54+
RELEASE_TAG="$RELEASE_TAG-nightly"
55+
fi
56+
set -e
57+
58+
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV
59+
echo "OVERRIDE_RELEASE=true" >> $GITHUB_ENV
60+
61+
- name: Create Release Tag from tag
62+
if: startsWith(github.ref, 'refs/tags/')
63+
run: |
64+
RELEASE_TAG=$(echo ${GITHUB_REF#refs/tags/})
65+
66+
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV
67+
echo "OVERRIDE_RELEASE=false" >> $GITHUB_ENV
68+
69+
- name: Build And Release
70+
env:
71+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
72+
RELEASE_TITLE: "kloudlite-k3s-runner"
73+
RELEASE_NOTES: "kloudlite k3s runner"
74+
GOARCH: ${{matrix.target_arch}}
75+
run: |
76+
pushd cmd/k3s-runner
77+
78+
task build
79+
80+
PRE_RELEASE=$OVERRIDE_RELEASE
81+
82+
opts=("-R" "${{ github.repository }}")
83+
84+
release=$(gh release list ${opts[@]} | tail -n +1 | (grep -iE "\s+$RELEASE_TAG\s+" || echo -n "") | awk '{print $3}')
85+
86+
if [[ -z $release ]]; then
87+
echo "going to create release, as RELEASE ($RELEASE_TAG) does not exist"
88+
createOpts="${opts[@]}"
89+
if [ $PRE_RELEASE = "true" ]; then
90+
createOpts+=("--prerelease")
91+
fi
92+
93+
if ! [[ -z $RELEASE_TITLE ]]; then
94+
createOpts+=("--title" "'$RELEASE_TITLE'")
95+
fi
96+
createOpts+=("--notes" "'$RELEASE_NOTES'")
97+
98+
echo "creating github release with cmd: \`gh release create $RELEASE_TAG ${createOpts[@]}\` "
99+
eval gh release create "$RELEASE_TAG" ${createOpts[@]} --generate-notes
100+
fi
101+
102+
uploadOpts="${opts[@]}"
103+
if [ "$OVERRIDE_RELEASE" = "true" ]; then
104+
uploadOpts+=("--clobber")
105+
fi
106+
107+
echo "uploading buillt binary with cmd: \`gh release upload $RELEASE_TAG ${uploadOpts[*]} bin/*\`"
108+
gh release upload "$RELEASE_TAG" ${uploadOpts[@]} bin/*

Dockerfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#syntax=docker/dockerfile:1.4
22
FROM alpine:3.16
3-
4-
RUN apk add bash curl gettext zip
5-
RUN apk add terraform helm kubectl --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community
6-
RUN apk add jq
7-
3+
RUN apk add bash curl gettext zip jq
4+
# RUN apk add terraform helm kubectl --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community
5+
RUN apk add helm kubectl --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community
6+
RUN curl -L0 https://releases.hashicorp.com/terraform/1.5.7/terraform_1.5.7_linux_amd64.zip > tf.zip && unzip tf.zip && mv terraform /usr/local/bin && rm tf.zip
87
RUN adduser --disabled-password --home="/app" --uid 1717 nonroot
98
USER nonroot
109
WORKDIR /app
1110
COPY --chown=nonroot ./terraform ./terraform
12-
RUN mkdir infrastructure-templates
11+
RUN mkdir -p infrastructure-templates
1312
COPY --chown=nonroot ./infrastructure-templates ./infrastructure-templates
1413
ENV TF_PLUGIN_CACHE_DIR="/app/.terraform.d/plugin-cache"
1514
RUN mkdir -p $TF_PLUGIN_CACHE_DIR

Taskfile.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ tasks:
1515
msg: 'var Tag must have a value'
1616
silent: true
1717
cmds:
18-
# - docker build -t {{.Image}} .
19-
# - docker push {{.Image}}
20-
- podman buildx build -t {{.Image}} .
21-
- podman push {{.Image}}
18+
- docker build -t {{.Image}} .
19+
- docker push {{.Image}}
20+
# - podman buildx build -t {{.Image}} .
21+
# - podman push {{.Image}}
2222

2323
tf:download:kubeconfig:dev:
2424
vars:

cmd/k3s-runner/Taskfile.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@ tasks:
55
env:
66
CGO_ENABLED: 0
77
GOOS: linux
8-
GOARCH: amd64
98
vars:
109
builtAt:
1110
sh: date | sed 's/\s/_/g'
1211
cmds:
13-
- go build -ldflags="-s -w -X main.BuiltAt={{.builtAt}}" -o ./bin/runner .
14-
- upx bin/runner
12+
- go build -ldflags="-s -w -X main.BuiltAt={{.builtAt}}" -o ./bin/runner-${GOARCH:-$(go env GOARCH)} .
13+
- upx bin/runner-${GOARCH:-$(go env GOARCH)}
1514

1615
help:
1716
summary: |+
1817
to run as primaryMaster, create a `/runner-config.yml` file, with following contents:
19-
```
20-
runAs: primaryMaster
21-
primaryMaster:
22-
publicIP: <ip-address>
23-
token: sample
24-
nodeName: k8s-master-1
25-
```
18+
```
19+
runAs: primaryMaster
20+
primaryMaster:
21+
publicIP: <ip-address>
22+
token: sample
23+
nodeName: k8s-master-1
24+
```

terraform/modules/kloudlite/deployments/kloudlite-agent.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ resource "ssh_resource" "install-kloudlite-agent" {
4848
image = "ghcr.io/kloudlite/operator/helm-charts:${var.kloudlite_release}"
4949

5050
service_account_name = local.service_account_name
51-
51+
kloudlite_release = var.kloudlite_release
5252
})
5353
destination = "${local.dir}/helm-charts-controller.yml"
5454
}

terraform/modules/kloudlite/deployments/templates/helm-charts-controller.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ spec:
4141
cpu: 5m
4242
memory: 10Mi
4343

44-
- command:
45-
- /manager
46-
args:
44+
- args:
4745
- --health-probe-bind-address=:8081
4846
- --metrics-bind-address=127.0.0.1:8080
4947
- --leader-elect
@@ -56,6 +54,8 @@ spec:
5654
value: "30s"
5755
- name: MAX_CONCURRENT_RECONCILES
5856
value: "1"
57+
- name: HELM_JOB_RUNNER_IMAGE
58+
value: "ghcr.io/kloudlite/operator/workers/helm-runner:${kloudlite_release}"
5959
name: manager
6060
securityContext:
6161
runAsNonRoot: true

0 commit comments

Comments
 (0)