Skip to content

Commit

Permalink
added deploy job
Browse files Browse the repository at this point in the history
  • Loading branch information
parkersarahl committed Jul 30, 2024
1 parent 08c5a2e commit 3e956bf
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 4 deletions.
29 changes: 27 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,33 @@ jobs:
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./frontend
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
Explore-GitHub-Actions:
deploy:
name: Deploy to EKS
runs-on: arc-runner-set
steps:
- run: echo "🎉 This job uses runner scale set runners!"
- name: Checkout
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{secrets.AWS_REGION}}
- name: Intall Helm
run: |
echo "installing helm..."
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
- name: Configure Kubectl
run: |
echo "configuring kubectl"
aws eks update-kubeconfig --name${{secrets.K8S_CLUSTER_NAME}} --region${{secrets.AWS_REGION}}
- name: Install/Update Helm Chart
run: |
echo "installing/updating helm chart..."
helm upgrade --install todo-app ./todo --set database.host=${{secrets.DB_HOST}} --set database.username=${{secrets.DB_USERNAME}} --set database.password=${{secrets.DB_PASSWORD}} --set api.image.repository=${{secrets.API_IMAGE_URI}} --set frontend.image.repository=${{secrets.FRONTEND_IMAGE_URI}}
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
k8s/
todo/

23 changes: 23 additions & 0 deletions todo/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions todo/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: todo
description: A Helm chart to deploy our todo app to Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
23 changes: 23 additions & 0 deletions todo/templates/api/database-migration-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: batch/v1
kind: Job
metadata:
name: database-migration-job-{{ .Values.api.image.tag}}
spec:
ttlSecondsAfterFinished: 10
template:
spec:
containers:
- name: database-migration-job
image: {{ .Values.api.image.repository}}:{{ .Values.api.image.tag}}
env:
- name: DB_HOST
value: {{ .Values.database.host}}
- name: DB_USERNAME
value: {{ .Values.database.username}}
- name: DB_PASSWORD
value: {{ .Values.database.password}}
- name: ENVIRONMENT
value: {{ .Values.environment}}
command: ["npm", "run", "migration:run", ]
restartPolicy: Never
backoffLimit: 1
33 changes: 33 additions & 0 deletions todo/templates/api/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: todo-api-deployment
labels:
app: todo
tier: api
spec:
replicas: 3
selector:
matchLabels:
app: todo
tier: api
template:
metadata:
labels:
app: todo
tier: api
spec:
containers:
- name: todo-api
env:
- name: DB_HOST
value: {{ .Values.database.host}}
- name: DB_USERNAME
value: {{ .Values.database.username}}
- name: DB_PASSWORD
value: {{ .Values.database.password}}
- name: ENVIRONMENT
value: {{ .Values.environment}}
image: {{ .Values.api.image.repository}}:{{ .Values.api.image.tag}}
ports:
- containerPort: 80
16 changes: 16 additions & 0 deletions todo/templates/api/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: todo-api-service
labels:
apps: todo
tier: api
spec:
selector:
app: todo
tier: api

ports:
- protocol: TCP
port: 3000
targetPort: 3000
24 changes: 24 additions & 0 deletions todo/templates/frontend/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: todo-frontend-deployment
labels:
app: todo
tier: frontend
spec:
replicas: 3
selector:
matchLabels:
app: todo
tier: frontend
template:
metadata:
labels:
app: todo
tier: frontend
spec:
containers:
- name: todo-frontend
image: {{ .Values.frontend.image.repository}}:{{ .Values.frontend.image.tag}}
ports:
- containerPort: 80
16 changes: 16 additions & 0 deletions todo/templates/frontend/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: todo-frontend-service
labels:
apps: todo
tier: frontend
spec:
selector:
app: todo
tier: frontend

ports:
- protocol: TCP
port: 80
targetPort: 80
24 changes: 24 additions & 0 deletions todo/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: todo-ingress

spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: todo-frontend-service
port:
number: 80
- path: /api
pathType: Prefix
backend:
service:
name: todo-api-service
port:
number: 3000
21 changes: 21 additions & 0 deletions todo/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Default values for todo.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

database:
host: ""
username: ""
password: ""

environment: production

api:
image:
repository: ""
tag: v2

frontend:
image:
repository: ""
tag: v2

0 comments on commit 3e956bf

Please sign in to comment.