Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/call-docker-build-result.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ on:
push:
branches:
- 'main'
- 'feature/terraform-setup'
# only build when important files change
paths:
- 'result/**'
- '.github/workflows/call-docker-build-result.yaml'
pull_request:
branches:
- 'main'
- 'feature/terraform-setup'
# only build when important files change
paths:
- 'result/**'
Expand Down Expand Up @@ -44,24 +46,22 @@ jobs:
### ENABLE ONE OR BOTH REGISTRIES
### tell docker where to push.
### NOTE if Docker Hub is set to true, you must set secrets above and also add account/repo/tags below
dockerhub-enable: true
dockerhub-enable: false
ghcr-enable: true

### REQUIRED
### A list of the account/repo names for docker build. List should match what's enabled above
### defaults to:
image-names: |
ghcr.io/dockersamples/example-voting-app-result
dockersamples/examplevotingapp_result
ghcr.io/emah1/example-voting-app-result

### REQUIRED set rules for tagging images, based on special action syntax:
### https://github.com/docker/metadata-action#tags-input
### defaults to:
tag-rules: |
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
type=raw,value=before,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
type=raw,value=after,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag

### path to where docker should copy files into image
### defaults to root of repository (.)
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/call-docker-build-vote.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ on:
push:
branches:
- 'main'
- 'feature/terraform-setup'
# only build when important files change
paths:
- 'vote/**'
- '.github/workflows/call-docker-build-vote.yaml'
pull_request:
branches:
- 'main'
- 'feature/terraform-setup'
# only build when important files change
paths:
- 'vote/**'
Expand Down Expand Up @@ -44,24 +46,22 @@ jobs:
### ENABLE ONE OR BOTH REGISTRIES
### tell docker where to push.
### NOTE if Docker Hub is set to true, you must set secrets above and also add account/repo/tags below
dockerhub-enable: true
dockerhub-enable: false
ghcr-enable: true

### REQUIRED
### A list of the account/repo names for docker build. List should match what's enabled above
### defaults to:
image-names: |
ghcr.io/dockersamples/example-voting-app-vote
dockersamples/examplevotingapp_vote
ghcr.io/emah1/example-voting-app-vote

### REQUIRED set rules for tagging images, based on special action syntax:
### https://github.com/docker/metadata-action#tags-input
### defaults to:
tag-rules: |
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
type=raw,value=before,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
type=raw,value=after,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag

### path to where docker should copy files into image
### defaults to root of repository (.)
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/call-docker-build-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ on:
push:
branches:
- 'main'
- 'feature/terraform-setup'
# only build when important files change
paths:
- 'worker/**'
- '.github/workflows/call-docker-build-worker.yaml'
pull_request:
branches:
- 'main'
- 'feature/terraform-setup'
# only build when important files change
paths:
- 'worker/**'
Expand Down Expand Up @@ -44,22 +46,21 @@ jobs:
### ENABLE ONE OR BOTH REGISTRIES
### tell docker where to push.
### NOTE if Docker Hub is set to true, you must set secrets above and also add account/repo/tags below
dockerhub-enable: true
dockerhub-enable: false
ghcr-enable: true

### REQUIRED
### A list of the account/repo names for docker build. List should match what's enabled above
### defaults to:
image-names: |
ghcr.io/dockersamples/example-voting-app-worker
dockersamples/examplevotingapp_worker

ghcr.io/emah1/example-voting-app-worker
### REQUIRED set rules for tagging images, based on special action syntax:
### https://github.com/docker/metadata-action#tags-input
### defaults to:
tag-rules: |
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag

### path to where docker should copy files into image
### defaults to root of repository (.)
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/terraform-validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Terraform Validation

on:
push:
branches:
- main
- feature/terraform-setup
paths:
- 'terraform/**'
- '.github/workflows/terraform-validate.yml'
pull_request:
branches:
- main
paths:
- 'terraform/**'
- '.github/workflows/terraform-validate.yml'

permissions:
contents: read

jobs:
validate:
name: Format and Validate Terraform
runs-on: ubuntu-latest

defaults:
run:
working-directory: terraform

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Terraform
uses: hashicorp/setup-terraform@v3

- name: Check formatting
run: terraform fmt -check -recursive

- name: Initialize Terraform without a backend
run: terraform init -backend=false -input=false

- name: Validate configuration
run: terraform validate
46 changes: 46 additions & 0 deletions .github/workflows/validate-voting-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

name: Validate Voting App

on:
push:
branches:
- main
- feature/three-voting-options
- feature/terraform-setup
pull_request:
branches:
- main

permissions:
contents: read

jobs:
validate:
name: Validate and Build
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Check Python syntax
run: python -m py_compile vote/app.py

- name: Check patch formatting
run: git diff --check origin/main...HEAD

- name: Build Vote image
run: docker build -t voting-app-vote:ci ./vote

- name: Build Result image
run: docker build -t voting-app-result:ci ./result

- name: Build Worker image
run: docker build -t voting-app-worker:ci ./worker
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ bin/
obj/
.vs/
node_modules/
# Terraform
**/.terraform/*
*.tfstate
*.tfstate.*
crash.log
crash.*.log
.local/
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ services:
build:
context: ./vote
target: dev
environment:
OPTION_A: "NDC / Peter Obi"
OPTION_B: "ADC / Atiku"
OPTION_C: "APC / Tinubu"
depends_on:
redis:
condition: service_healthy
Expand Down
6 changes: 6 additions & 0 deletions helm/voting-app/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: voting-app
description: Local Kubernetes Helm chart for the Voting App
type: application
version: 0.1.0
appVersion: "1.0.0"
76 changes: 76 additions & 0 deletions helm/voting-app/templates/db.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ .Release.Name }}-db
type: Opaque
stringData:
username: {{ .Values.postgres.username | quote }}
password: {{ .Values.postgres.password | quote }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ .Release.Name }}-db-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.postgres.storage }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-db
spec:
replicas: 1
selector:
matchLabels:
app: {{ .Release.Name }}-db
template:
metadata:
labels:
app: {{ .Release.Name }}-db
spec:
containers:
- name: postgres
image: postgres:15-alpine
ports:
- containerPort: 5432
env:
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-db
key: username
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-db
key: password
- name: POSTGRES_DB
value: {{ .Values.postgres.database | quote }}
readinessProbe:
exec:
command: ["sh", "-c", "pg_isready -U \"$POSTGRES_USER\" -d \"$POSTGRES_DB\""]
initialDelaySeconds: 5
periodSeconds: 5
volumeMounts:
- name: db-data
mountPath: /var/lib/postgresql/data
volumes:
- name: db-data
persistentVolumeClaim:
claimName: {{ .Release.Name }}-db-data
---
apiVersion: v1
kind: Service
metadata:
name: db
spec:
selector:
app: {{ .Release.Name }}-db
ports:
- name: postgres
port: 5432
targetPort: 5432
36 changes: 36 additions & 0 deletions helm/voting-app/templates/redis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-redis
spec:
replicas: 1
selector:
matchLabels:
app: {{ .Release.Name }}-redis
template:
metadata:
labels:
app: {{ .Release.Name }}-redis
spec:
containers:
- name: redis
image: redis:alpine
ports:
- containerPort: 6379
readinessProbe:
exec:
command: ["redis-cli", "ping"]
initialDelaySeconds: 3
periodSeconds: 5
---
apiVersion: v1
kind: Service
metadata:
name: redis
spec:
selector:
app: {{ .Release.Name }}-redis
ports:
- name: redis
port: 6379
targetPort: 6379
Loading