Create ephemeral environment Docker image for ubuntu/debian base and output k8s manifests #13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Create ephemeral environment Docker image | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| container_name: | |
| description: "Container name" | |
| required: false | |
| default: "app" # container name. APP_NAME is used on k8s labels/selectors. | |
| base_image: | |
| description: "Base image to build from" | |
| required: true | |
| default: "python:3.12-slim" | |
| name: | |
| description: "Name of the environment" | |
| required: false | |
| default: "riley-minikube-python" | |
| packages: | |
| description: "Packages to install on base image" | |
| required: false | |
| cpu: | |
| description: "CPU allocation" | |
| required: true | |
| default: "256m" | |
| memory: | |
| description: "Memory allocation" | |
| required: true | |
| default: "512Mi" | |
| push_to_dockerhub: | |
| description: "Push built image to dockerhub" | |
| required: false | |
| default: "false" | |
| hpa_enabled: | |
| description: "Enable HPA" | |
| required: false | |
| default: "false" | |
| hpa_min_replicas: | |
| description: "HPA min replicas" | |
| required: false | |
| default: "1" | |
| hpa_max_replicas: | |
| description: "HPA max replicas" | |
| required: false | |
| default: "3" | |
| hpa_cpu_target_percentage: | |
| description: "HPA CPU target percentage" | |
| required: false | |
| default: "60" | |
| jobs: | |
| deploy-docker-k8s: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| - name: Show selected inputs | |
| run: | | |
| echo "Base image to build: ${{ github.event.inputs.base_image }}" | |
| echo "Environment name: ${{ github.event.inputs.name }}" | |
| echo "Packages to be installed: ${{ github.event.inputs.packages }}" | |
| echo "CPU Requested: ${{ github.event.inputs.cpu }}" | |
| echo "Memory Requested: ${{ github.event.inputs.memory }}" | |
| - name: Export template variables | |
| run: | | |
| cat <<EOF >> $GITHUB_ENV | |
| DEPLOYMENT_NAME=${{ github.event.inputs.name }} | |
| SERVICE_NAME=${{ github.event.inputs.name }} | |
| # APP_NAME=${{ github.event.inputs.name }} | |
| APP_NAME=app-${{ github.actor }}-${{ github.event.inputs.name }}-${{ github.run_number }} | |
| CONTAINER_NAME=${{ github.event.inputs.container_name }} | |
| IMAGE=${{ github.event.inputs.base_image }} | |
| CPU_REQUEST=${{ github.event.inputs.cpu }} | |
| MEMORY_REQUEST=${{ github.event.inputs.memory }} | |
| CPU_LIMIT=${{ github.event.inputs.cpu }} | |
| MEMORY_LIMIT=${{ github.event.inputs.memory }} | |
| HPA_ENABLED=${{ github.event.inputs.hpa_enabled }} | |
| HPA_MIN_REPLICAS=${{ github.event.inputs.hpa_min_replicas }} | |
| HPA_MAX_REPLICAS=${{ github.event.inputs.hpa_max_replicas }} | |
| HPA_CPU_TARGET_PERCENTAGE=${{ github.event.inputs.hpa_cpu_target_percentage }} | |
| SERVICE_PORT=80 | |
| TARGET_PORT=8080 | |
| EOF | |
| - name: Render Kubernetes manifests | |
| run: | | |
| envsubst < ops/deploy.tpl.yaml > ops/deploy.yaml | |
| envsubst < ops/service.tpl.yaml > ops/service.yaml | |
| if [ "${HPA_ENABLED}" = "true" ]; then | |
| envsubst < ops/hpa.tpl.yaml > ops/hpa.yaml | |
| fi | |
| - name: Validate Kubernetes for Deployment # Of course, this would not be a dry run if I had a real cluster to deploy to. | |
| uses: docker://ghcr.io/yannh/kubeconform:latest | |
| with: | |
| args: "-strict -ignore-missing-schemas ops/*.yaml" | |
| - name: Upload rendered manifests as build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: k8s-manifests-${{ github.event.inputs.name }} | |
| path: | | |
| ops/deploy.yaml | |
| ops/service.yaml | |
| ops/hpa.yaml |