-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (119 loc) · 4.64 KB
/
dev_dispatch.yml
File metadata and controls
143 lines (119 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Create ephemeral environment Docker image for ubuntu/debian base and output k8s manifests
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. Supports debian/ubuntu based images"
required: true
default: "ubuntu:22.04"
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/deploy.yaml ops/service.yaml ops/hpa.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
- name: Set up Docker Buildx
if: github.event.inputs.push_to_dockerhub == 'true'
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
if: github.event.inputs.push_to_dockerhub == 'true'
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push image
if: github.event.inputs.push_to_dockerhub == 'true'
uses: docker/build-push-action@v6
with:
context: .
push: true
build-args: |
BASE_IMAGE=${{ github.event.inputs.base_image }}
tags: |
sadminriley/${{ github.event.inputs.name }}:latest
sadminriley/${{ github.event.inputs.name }}:${{ github.run_number }}