Compare commits
10 commits
acec852010
...
72d570731d
| Author | SHA1 | Date | |
|---|---|---|---|
| 72d570731d | |||
| b305152e9f | |||
| 6a94eb6279 | |||
| e79d57928a | |||
| edcc936564 | |||
| c9073c61d2 | |||
| 44a237aed4 | |||
| 94931ef4e3 | |||
| 22ff2f2c04 | |||
| ae138368b1 |
5 changed files with 122 additions and 3 deletions
2
.hadolint.yaml
Normal file
2
.hadolint.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
ignored:
|
||||
- DL3008
|
||||
25
Dockerfile
Normal file
25
Dockerfile
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# Container image that runs your code
|
||||
FROM debian:12.8-slim
|
||||
|
||||
# compare https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/
|
||||
|
||||
# https://stackoverflow.com/a/69684246
|
||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||
|
||||
RUN apt-get update && \
|
||||
export DEBIAN_FRONTEND=noninteractive && \
|
||||
apt-get install --no-install-recommends -y git nodejs gpg npm dnsutils \
|
||||
apt-transport-https ca-certificates curl gnupg && \
|
||||
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.32/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg && \
|
||||
chmod 644 /etc/apt/keyrings/kubernetes-apt-keyring.gpg && \
|
||||
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.32/deb/ /' | tee /etc/apt/sources.list.d/kubernetes.list && \
|
||||
chmod 644 /etc/apt/sources.list.d/kubernetes.list && \
|
||||
apt-get update && apt-get install -y --no-install-recommends kubectl && \
|
||||
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||
|
||||
# Copies your code file from your action repository to the filesystem path `/` of the container
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
# Code file to execute when the docker container starts up (`entrypoint.sh`)
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
||||
34
README.md
34
README.md
|
|
@ -3,6 +3,34 @@
|
|||
This is a [Github Action](https://docs.github.com/en/actions/sharing-automations/creating-actions/creating-a-docker-container-action)
|
||||
using Docker, with the intention to efficiently deploy to a k3s or k8s cluster using kustomize.
|
||||
|
||||
# How to Use
|
||||
|
||||
## How to Configure in .github/workflows/main.yaml
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
deploy_staging:
|
||||
steps:
|
||||
- name: deploy to staging
|
||||
id: deploy
|
||||
uses: https://gitea.uber5.com/Uber5-Public/gha-deploy-to-k3s@v2
|
||||
with:
|
||||
kust_config: kustomize/overlays/testing
|
||||
env:
|
||||
K3S_YAML: ${{ secrets.K3S_YAML }} # assuming that K3S_YAML is defined in a README, see also below
|
||||
- name: Check output of previous step (kinda dummy)
|
||||
run: echo "The start time was ${{ steps.deploy.outputs.time }}"
|
||||
```
|
||||
|
||||
## How to Setup K3S_YAML
|
||||
|
||||
We assume you use k3s. Otherwise, use comparable kubectl configuration.
|
||||
|
||||
- Grab k3s.yaml (\`/etc/rancher/k3s/k3s.yaml\`), copy it to /tmp/ and make it readable for you, then copy it from the master node of the k3s cluster: `scp your-node-123.uber5.com:/tmp/k3s.yaml /tmp/`
|
||||
- Change the `server` entry to use its public DNS name
|
||||
- Insert `tls-server-name: worker1` underneath the `server` key. The value (`worker1` in this case) needs to be one of the names that are in the cert. If you get it wrong, the error message in the pipeline will tell you.
|
||||
- encode k3s.yaml with `base64 -i /tmp/k3s.yaml -o /tmp/encoded`, and set it as the value for a secret `K3S_YAML` in gitea for the repository under "Settings > Actions > Secrets"
|
||||
|
||||
# Open Questions
|
||||
|
||||
- We use [kustomize](https://kustomize.io/). Is this overkill? As the complexity of deployments is not that high, usually, this may be more technical complexity than necessary. We could go back to using plain kubernetes manifests, and just have different ones for staging and prod.
|
||||
|
|
@ -10,6 +38,6 @@ using Docker, with the intention to efficiently deploy to a k3s or k8s cluster u
|
|||
- Advantages Github Actions:
|
||||
- execution time should be faster
|
||||
- it's closer to the mainstream
|
||||
- Advantages Woodpecker:
|
||||
- Current deployments use woodpecker already
|
||||
- Simpler technology (This is debatable)
|
||||
- Advantages Woodpecker:
|
||||
- Current deployments use woodpecker already
|
||||
- Simpler technology (This is debatable)
|
||||
|
|
|
|||
16
action.yml
Normal file
16
action.yml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# action.yml
|
||||
name: "Hello World"
|
||||
description: "Greet someone and record the time"
|
||||
inputs:
|
||||
kust_config: # id of input
|
||||
description: "the kustomization configuration, e.g. kustomize/overlays/testing"
|
||||
required: true
|
||||
default: "kustomize/overlays/testing"
|
||||
outputs:
|
||||
time: # id of output
|
||||
description: "The time we started"
|
||||
runs:
|
||||
using: "docker"
|
||||
image: "Dockerfile"
|
||||
args:
|
||||
- ${{ inputs.kust_config }}
|
||||
48
entrypoint.sh
Executable file
48
entrypoint.sh
Executable file
|
|
@ -0,0 +1,48 @@
|
|||
#!/bin/sh -l
|
||||
|
||||
set -e # fail if any command fails
|
||||
|
||||
time=$(date)
|
||||
echo "time=$time" >>"$GITHUB_OUTPUT"
|
||||
echo "env:"
|
||||
env
|
||||
echo "github output:"
|
||||
cat "$GITHUB_OUTPUT"
|
||||
|
||||
KUST_CONFIG=$1
|
||||
|
||||
if [ -z "$KUST_CONFIG" ]; then
|
||||
echo "KUST_CONFIG not defined, pass it in a 'with:' clause to the action" && exit 1
|
||||
fi
|
||||
if [ -z "$K3S_YAML" ]; then
|
||||
echo "K3S_YAML not defined, pass it in the environment with an 'env:' clause to the action" && exit 1
|
||||
fi
|
||||
if [ -z "$GITHUB_SHA" ]; then
|
||||
echo "GITHUB_SHA not defined, pass it in the environment with an 'env:' clause to the action" && exit 1
|
||||
fi
|
||||
|
||||
echo "Going to apply kustomization configuration at ${KUST_CONFIG}"
|
||||
echo "K3S_YAML:"
|
||||
echo "$K3S_YAML"
|
||||
echo "$K3S_YAML" | base64 -d >/tmp/k3s.yaml
|
||||
chmod 600 /tmp/k3s.yaml
|
||||
ls -lth /tmp/
|
||||
echo "K3S_YAML, deserialized:"
|
||||
cat /tmp/k3s.yaml
|
||||
cp -r ./kustomize /tmp/ # TODO: we expect the kustomize folder to be present in the root of the repository
|
||||
find /tmp/kustomize -type f -print0 | xargs -0 sed -i "s/GIT_VERSION/${GITHUB_SHA}/"
|
||||
# echo "try and get nodes and version... (debugging)"
|
||||
# kubectl --kubeconfig /tmp/k3s.yaml get all
|
||||
# kubectl --kubeconfig /tmp/k3s.yaml version
|
||||
echo "determine kustomize version..."
|
||||
KUSTOMIZE_VERSION=$(kubectl --kubeconfig /tmp/k3s.yaml version | grep Kustomize | awk '{ print $3 }')
|
||||
echo "KUSTOMIZE_VERSION=${KUSTOMIZE_VERSION}"
|
||||
# echo "run kustomize, and print output to console"
|
||||
# kubectl --kubeconfig /tmp/k3s.yaml kustomize "/tmp/${KUST_CONFIG}"
|
||||
echo "replace faulty kustomize version (compare https://github.com/kubernetes/kubectl/issues/1495)"
|
||||
kubectl --kubeconfig /tmp/k3s.yaml kustomize "/tmp/${KUST_CONFIG}" | sed "s/kustomize-(devel)/kustomize-$KUSTOMIZE_VERSION/" >/tmp/manifests.yaml
|
||||
echo "UPDATED YAML:"
|
||||
cat /tmp/manifests.yaml
|
||||
echo "applying..."
|
||||
kubectl --kubeconfig /tmp/k3s.yaml apply -f - </tmp/manifests.yaml
|
||||
echo "Done applying kustomized manifests at ${KUST_CONFIG}, success"
|
||||
Loading…
Add table
Add a link
Reference in a new issue