Skip to content

Commit d9bf45f

Browse files
committed
feat: add Dockerfile, helm chart and workflow for static site deployment to EKS
1 parent 44759be commit d9bf45f

15 files changed

Lines changed: 548 additions & 3 deletions

.github/workflows/eks-deploy.yaml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: "Deploy to EKS"
2+
on:
3+
push:
4+
branches:
5+
- "main"
6+
release:
7+
types:
8+
- "created"
9+
10+
jobs:
11+
deploy:
12+
name: "Setup, Build, Publish, and Deploy"
13+
runs-on: ubuntu-latest
14+
environment: "preview"
15+
env:
16+
# Infrastructure configuration
17+
EKS_CLUSTER: "war-eks-cluster"
18+
EKS_NAMESPACE: "prod"
19+
AWS_REGION: "eu-west-2"
20+
RELEASE_NAME: "watchflow-dev-landing"
21+
PUBLIC_DOMAIN: "watchflow.dev"
22+
ECR_REPOSITORY: "watchflow_dev_landing"
23+
24+
# Certificate configuration
25+
CERT_ISSUER_NAME: "war-cert-issuer"
26+
27+
# Application configuration
28+
PORT: "5500"
29+
HELM_PATH: "helm-chart"
30+
JOB_STATUS: "succeeded"
31+
32+
# AWS credentials
33+
AWS_ACCESS_KEY_ID: "${{ secrets.AWS_ACCESS_KEY_ID }}"
34+
AWS_SECRET_ACCESS_KEY: "${{ secrets.AWS_SECRET_ACCESS_KEY }}"
35+
36+
37+
permissions:
38+
contents: "read"
39+
id-token: "write"
40+
packages: "write"
41+
42+
steps:
43+
# Checkout the repository code
44+
- name: "Checkout"
45+
uses: actions/checkout@v4
46+
47+
# Configure AWS credentials for EKS and ECR access
48+
- name: "Configure AWS credentials"
49+
uses: aws-actions/configure-aws-credentials@v4
50+
with:
51+
aws-access-key-id: "${{ env.AWS_ACCESS_KEY_ID }}"
52+
aws-secret-access-key: "${{ env.AWS_SECRET_ACCESS_KEY }}"
53+
aws-region: "${{ env.AWS_REGION }}"
54+
55+
# Login to Amazon ECR to push Docker images
56+
- name: "Login to Amazon ECR"
57+
id: login-ecr
58+
uses: aws-actions/amazon-ecr-login@v2
59+
60+
# Build and push Docker image to ECR
61+
- name: "Build, tag, and push image to Amazon ECR"
62+
id: ecr-push
63+
env:
64+
ECR_REGISTRY: "${{ steps.login-ecr.outputs.registry }}"
65+
ECR_REPOSITORY: "${{ env.ECR_REPOSITORY }}"
66+
IMAGE_TAG: "${{ github.sha }}"
67+
run: |
68+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
69+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
70+
echo "image_repository=$ECR_REGISTRY/$ECR_REPOSITORY" >> $GITHUB_OUTPUT
71+
72+
# Update kubeconfig to connect to EKS cluster
73+
- name: "Update kubeconfig"
74+
run: aws eks update-kubeconfig --region "${{ env.AWS_REGION }}" --name "${{ env.EKS_CLUSTER }}"
75+
76+
# Deploy application using Helm chart
77+
- name: "Install or upgrade helm chart"
78+
env:
79+
IMAGE_TAG: "${{ github.sha }}"
80+
IMAGE_REPOSITORY: "${{ steps.ecr-push.outputs.image_repository }}"
81+
run: |-
82+
helm upgrade "${{ env.RELEASE_NAME }}" "${{ env.HELM_PATH }}" --namespace "${{ env.EKS_NAMESPACE }}" \
83+
--values "${{ env.HELM_PATH }}/values.yaml" \
84+
--set image.repository=${{ env.IMAGE_REPOSITORY }} \
85+
--set image.tag=${{ env.IMAGE_TAG }} \
86+
--set ingress.hosts[0].host=${{ env.PUBLIC_DOMAIN }} \
87+
--set ingress.tls[0].secretName=${{ env.RELEASE_NAME }}-tls \
88+
--set ingress.tls[0].hosts[0]=${{ env.PUBLIC_DOMAIN }} \
89+
--set cert.enabled=true \
90+
--set cert.tls.secretName=${{ env.RELEASE_NAME }}-tls \
91+
--set cert.issuerRef.name=${{ env.CERT_ISSUER_NAME }} \
92+
--set cert.issuerRef.kind=ClusterIssuer \
93+
--set cert.commonName=${{ env.PUBLIC_DOMAIN }} \
94+
--set cert.dnsNames.hosts[0]=${{ env.PUBLIC_DOMAIN }} \
95+
--set service.port=${{ env.PORT }} \
96+
--install
97+
shell: bash
98+
99+
# Set status to failed on any's step failure
100+
- name: "Set status to failed on any's step failure"
101+
if: ${{ failure() }}
102+
run: echo "JOB_STATUS=failed" >> $GITHUB_ENV
103+
104+
# Exit with error on failure
105+
- name: "Exit with error on failure"
106+
if: ${{ failure() }}
107+
run: exit 1

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM nginx:alpine
2+
COPY index.html /usr/share/nginx/html/
3+
COPY style.css /usr/share/nginx/html/
4+
COPY script.js /usr/share/nginx/html/
5+
COPY stars.js /usr/share/nginx/html/
6+
EXPOSE 80

helm-chart/.helmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
5+
# Match any file or path named .helmignore
6+
.helmignore

helm-chart/Chart.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: watchflow
3+
description: A Helm chart for deploying Watchflow in Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "0.1.0"

helm-chart/templates/NOTES.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
1. Get the application URL by running these commands:
2+
{{- if .Values.ingress.enabled }}
3+
{{- range $host := .Values.ingress.hosts }}
4+
{{- range .paths }}
5+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
6+
{{- end }}
7+
{{- end }}
8+
{{- else if contains "NodePort" .Values.service.type }}
9+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "copilot.fullname" . }})
10+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
11+
echo http://$NODE_IP:$NODE_PORT
12+
{{- else if contains "LoadBalancer" .Values.service.type }}
13+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
14+
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "copilot.fullname" . }}'
15+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "copilot.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
16+
echo http://$SERVICE_IP:{{ .Values.service.port }}
17+
{{- else if contains "ClusterIP" .Values.service.type }}
18+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ .Release.Name }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
19+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
20+
echo "Visit http://127.0.0.1:8080 to use your application"
21+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
22+
{{- end }}

helm-chart/templates/_helpers.tpl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{{/*
2+
Create a default fully qualified app name.
3+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
4+
Use only the release name or the `fullnameOverride` value if provided.
5+
*/}}
6+
{{- define "copilot.fullname" -}}
7+
{{- default .Release.Name .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
8+
{{- end }}
9+
10+
{{/*
11+
Create chart name and version as used by the chart label.
12+
*/}}
13+
{{- define "copilot.chart" -}}
14+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
15+
{{- end }}
16+
17+
{{/*
18+
Common labels
19+
*/}}
20+
{{- define "copilot.labels" -}}
21+
helm.sh/chart: {{ include "copilot.chart" . }}
22+
{{ include "copilot.selectorLabels" . }}
23+
{{- if .Chart.AppVersion }}
24+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
25+
{{- end }}
26+
app.kubernetes.io/managed-by: {{ .Release.Service }}
27+
{{- end }}
28+
29+
{{/*
30+
Selector labels
31+
We're using just the release name.
32+
*/}}
33+
{{- define "copilot.selectorLabels" -}}
34+
app.kubernetes.io/name: {{ .Release.Name }}
35+
app.kubernetes.io/instance: {{ .Release.Name }}
36+
{{- end }}
37+
38+
{{/*
39+
Create the name of the service account to use.
40+
Use only the release name or the `serviceAccount.name` value if provided.
41+
*/}}
42+
{{- define "copilot.serviceAccountName" -}}
43+
{{- if .Values.serviceAccount.create }}
44+
{{- default .Release.Name .Values.serviceAccount.name }}
45+
{{- else }}
46+
{{- default "default" .Values.serviceAccount.name }}
47+
{{- end }}
48+
{{- end }}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{{- if .Values.cert.enabled }}
2+
apiVersion: cert-manager.io/v1
3+
kind: Certificate
4+
metadata:
5+
name: {{ include "copilot.fullname" . }}
6+
labels:
7+
{{- include "copilot.labels" . | nindent 4 }}
8+
spec:
9+
secretName: {{ .Values.cert.tls.secretName }}
10+
issuerRef:
11+
name: {{ .Values.cert.issuerRef.name }}
12+
kind: {{ .Values.cert.issuerRef.kind }}
13+
commonName: {{ .Values.cert.commonName }}
14+
dnsNames:
15+
{{ .Values.cert.dnsNames.hosts }}
16+
{{- end }}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "copilot.fullname" . }}
5+
labels:
6+
{{- include "copilot.labels" . | nindent 4 }}
7+
spec:
8+
{{- if not .Values.autoscaling.enabled }}
9+
replicas: {{ .Values.replicaCount }}
10+
{{- end }}
11+
selector:
12+
matchLabels:
13+
{{- include "copilot.selectorLabels" . | nindent 6 }}
14+
template:
15+
metadata:
16+
{{- with .Values.podAnnotations }}
17+
annotations:
18+
{{- toYaml . | nindent 8 }}
19+
{{- end }}
20+
labels:
21+
{{- include "copilot.selectorLabels" . | nindent 8 }}
22+
spec:
23+
{{- with .Values.imagePullSecrets }}
24+
imagePullSecrets:
25+
{{- toYaml . | nindent 8 }}
26+
{{- end }}
27+
serviceAccountName: {{ include "copilot.serviceAccountName" . }}
28+
securityContext:
29+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
30+
containers:
31+
- name: {{ .Chart.Name }}
32+
securityContext:
33+
{{- toYaml .Values.securityContext | nindent 12 }}
34+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
35+
imagePullPolicy: {{ .Values.image.pullPolicy }}
36+
ports:
37+
- name: http
38+
containerPort: {{ .Values.service.port }}
39+
protocol: TCP
40+
livenessProbe:
41+
httpGet:
42+
path: {{ .Values.healthChecks.path }}
43+
port: {{ .Values.service.port }}
44+
scheme: HTTP
45+
initialDelaySeconds: 60
46+
periodSeconds: 30
47+
failureThreshold: 5
48+
readinessProbe:
49+
httpGet:
50+
path: {{ .Values.healthChecks.path }}
51+
port: {{ .Values.service.port }}
52+
scheme: HTTP
53+
initialDelaySeconds: 60
54+
periodSeconds: 30
55+
failureThreshold: 5
56+
envFrom:
57+
- secretRef:
58+
name: {{ include "copilot.fullname" . }}
59+
resources:
60+
{{- toYaml .Values.resources | nindent 12 }}
61+
{{- if and .Values.volumeConfig (eq .Values.volumeConfig.enabled true) }}
62+
volumeMounts:
63+
- name: {{ .Values.volumeConfig.volumeName }}
64+
mountPath: {{ .Values.volumeConfig.mountPath }}
65+
{{- end }}
66+
{{- if and .Values.volumeConfig (eq .Values.volumeConfig.enabled true) }}
67+
volumes:
68+
- name: {{ .Values.volumeConfig.volumeName }}
69+
persistentVolumeClaim:
70+
claimName: {{ .Values.volumeConfig.persistentVolumeClaim.claimName }}
71+
{{- end }}
72+
{{- with .Values.nodeSelector }}
73+
nodeSelector:
74+
{{- toYaml . | nindent 8 }}
75+
{{- end }}
76+
{{- with .Values.affinity }}
77+
affinity:
78+
{{- toYaml . | nindent 8 }}
79+
{{- end }}
80+
{{- with .Values.tolerations }}
81+
tolerations:
82+
{{- toYaml . | nindent 8 }}
83+
{{- end }}

helm-chart/templates/hpa.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{- if .Values.autoscaling.enabled }}
2+
apiVersion: autoscaling/v2
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ include "copilot.fullname" . }}
6+
labels:
7+
{{- include "copilot.labels" . | nindent 4 }}
8+
spec:
9+
scaleTargetRef:
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
name: {{ include "copilot.fullname" . }}
13+
minReplicas: {{ .Values.autoscaling.minReplicas }}
14+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
15+
metrics:
16+
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
17+
- type: Resource
18+
resource:
19+
name: cpu
20+
target:
21+
type: Utilization
22+
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
23+
{{- end }}
24+
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
25+
- type: Resource
26+
resource:
27+
name: memory
28+
target:
29+
type: Utilization
30+
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
31+
{{- end }}
32+
{{- end }}

0 commit comments

Comments
 (0)