Compare commits
No commits in common. "main" and "v1" have entirely different histories.
10
Dockerfile
10
Dockerfile
@ -2,19 +2,15 @@
|
||||
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 && \
|
||||
apt-transport-https ca-certificates curl gnupg # packages in this line required for kubectl && \
|
||||
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 && \
|
||||
chmod 644 /etc/apt/sources.list.d/kubernetes.list # helps tools such as command-not-found to work correctly && \
|
||||
apt-get update && apt-get install -y 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
|
||||
|
34
README.md
34
README.md
@ -3,34 +3,6 @@
|
||||
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: kubernetes` underneath the `server` key. The value (`kubernetes` 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.
|
||||
@ -38,6 +10,6 @@ We assume you use k3s. Otherwise, use comparable kubectl configuration.
|
||||
- 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)
|
10
action.yml
10
action.yml
@ -2,15 +2,15 @@
|
||||
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"
|
||||
who-to-greet: # id of input
|
||||
description: "Who to greet"
|
||||
required: true
|
||||
default: "kustomize/overlays/testing"
|
||||
default: "World"
|
||||
outputs:
|
||||
time: # id of output
|
||||
description: "The time we started"
|
||||
description: "The time we greeted you"
|
||||
runs:
|
||||
using: "docker"
|
||||
image: "Dockerfile"
|
||||
args:
|
||||
- ${{ inputs.kust_config }}
|
||||
- ${{ inputs.who-to-greet }}
|
||||
|
@ -1,48 +1,5 @@
|
||||
#!/bin/sh -l
|
||||
|
||||
set -e # fail if any command fails
|
||||
|
||||
echo "Hello $1"
|
||||
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…
Reference in New Issue
Block a user