Skip to content

Commit

Permalink
Merge pull request #9 from mark3labs/dev
Browse files Browse the repository at this point in the history
Kubernetes updates
  • Loading branch information
ezynda3 authored May 16, 2024
2 parents 0f3eaa5 + ab40c0a commit 1cde2a7
Show file tree
Hide file tree
Showing 18 changed files with 259 additions and 116 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/ci.staging.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
name: build-and-deploy-staging

on:
push:
workflow_dispatch:
inputs:
job_id:
description: 'The unique ID for tracking'
required: true
branches:
- dev
run-name: build-and-deploy-staging:${{github.event.client_payload.id}}

run-name: build-and-deploy-staging:${{ inputs.job_id }}
jobs:
docker:
runs-on: ubuntu-latest
Expand Down
21 changes: 6 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
name: build-and-deploy-prod

on:
push:
workflow_dispatch:
inputs:
job_id:
description: 'The unique ID for tracking'
required: true
branches:
- master

run-name: build-and-deploy-prod:${{ inputs.job_id }}
jobs:
docker:
runs-on: ubuntu-latest
Expand All @@ -30,17 +35,3 @@ jobs:
tags: |
mark3labs/louper-web:${{ steps.vars.outputs.version }}
mark3labs/louper-web:latest
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

- name: Save DigitalOcean kubeconfig with short-lived credentials
run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 662138bb-8236-4da5-8c6d-c602fb6eef82

- name: Deploy to DigitalOcean Kubernetes
run: kubectl rollout restart deployment/louper

- name: Verify deployment
run: kubectl rollout status deployment/louper
3 changes: 2 additions & 1 deletion .github/workflows/rollout.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: rollout-prod

on:
workflow_dispatch:
schedule:
- cron: '0 0 */6 * * *'
- cron: '0 */6 * * *'

jobs:
docker:
Expand Down
6 changes: 4 additions & 2 deletions .k8s/deployment.yml → .k8s/base/deployment.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: louper
name: louper-deployment
namespace: louper
labels:
app: louper
spec:
Expand All @@ -15,7 +16,7 @@ spec:
app: louper
spec:
containers:
- name: louper-container
- name: louper-container-staging
image: mark3labs/louper-web:latest
volumeMounts:
- mountPath: '/app/data'
Expand All @@ -29,6 +30,7 @@ spec:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
namespace: louper
name: louper-db
spec:
accessModes:
Expand Down
6 changes: 6 additions & 0 deletions .k8s/base/kustomization.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- deployment.yml
- service.yml
1 change: 1 addition & 0 deletions .k8s/service.yml → .k8s/base/service.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apiVersion: v1
kind: Service
metadata:
namespace: louper
name: louper-service
spec:
type: NodePort
Expand Down
23 changes: 23 additions & 0 deletions .k8s/prod/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: louper
namespace: argocd
annotations:
argocd-image-updater.argoproj.io/image-list: louper=mark3labs/louper-web:latest
argocd-image-updater.argoproj.io/louper.update-strategy: digest
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: default
source:
repoURL: 'https://github.com/mark3labs/louper-v3.git'
path: .k8s/staging
targetRevision: master
destination:
server: 'https://kubernetes.default.svc'
namespace: louper
syncPolicy:
automated:
prune: true
selfHeal: true
46 changes: 46 additions & 0 deletions .k8s/prod/jobs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apiVersion: batch/v1
kind: Job
metadata:
namespace: louper-prod
name: github-ci
generatedName: build-image-and-push-
annotations:
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/hook-delete-policy: HookSucceeded
spec:
template:
spec:
containers:
- name: github-ci
image: pkgxdev/pkgx:latest
imagePullPolicy: Always
env:
- name: GITHUB_TOKEN
valueFrom:
secretKeyRef:
name: gh
key: token
command:
- /bin/bash
- -c
- |
apt update && apt install -y ca-certificates
pkgx install gh
pkgx install jq
pkgx install uuidgen
gh auth login
export JOB_ID=$(uuidgen)
echo "{\"job_id\": \"$JOB_ID\" }" | gh workflow run build-and-deploy-prod --repo mark3labs/louper-v3 --ref dev --json
STATUS="starting"
while [[ "$STATUS" != "completed" && "$STATUS" != "failure" ]]
do
STATUS=$(gh run list --workflow=build-and-deploy-prod --repo mark3labs/louper-v3 --json "status,name" | jq --arg i "build-and-deploy-prod:$JOB_ID" '.[] | select(.name == $i)' | jq -r '.status')
echo "Job Status: $STATUS"
sleep 1
done
resources:
limits:
cpu: 1
memory: 1Gi
restartPolicy: Never
8 changes: 8 additions & 0 deletions .k8s/prod/kustomization.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ../base
- namespace.yml
- application.yml
- jobs.yml
4 changes: 4 additions & 0 deletions .k8s/prod/namespace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: louper
23 changes: 23 additions & 0 deletions .k8s/staging/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: louper-staging
namespace: argocd
annotations:
argocd-image-updater.argoproj.io/image-list: louper=mark3labs/louper-web:staging-latest
argocd-image-updater.argoproj.io/louper.update-strategy: digest
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: default
source:
repoURL: 'https://github.com/mark3labs/louper-v3.git'
path: .k8s/staging
targetRevision: dev
destination:
server: 'https://kubernetes.default.svc'
namespace: louper-staging
syncPolicy:
automated:
prune: true
selfHeal: true
43 changes: 43 additions & 0 deletions .k8s/staging/deployment-patch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# apiVersion: apps/v1
# kind: Deployment
# metadata:
# name: louper-deployment
# namespace: louper
# labels:
# app: louper
# spec:
# replicas: 1
# selector:
# matchLabels:
# app: louper
# template:
# metadata:
# labels:
# app: louper
# spec:
# containers:
# - name: louper-container-staging
# image: mark3labs/louper-web:latest
# volumeMounts:
# - mountPath: '/app/data'
# name: volume
# imagePullPolicy: Always
# volumes:
# - name: volume
# persistentVolumeClaim:
# claimName: louper-db
# ---
# apiVersion: v1
# kind: PersistentVolumeClaim
# metadata:
# namespace: louper
# name: louper-db
# spec:
# accessModes:
# - ReadWriteOnce
# resources:
# requests:
# storage: 1Gi
- op: replace
path: /spec/template/spec/containers/0/image
value: mark3labs/louper-web:staging-latest
83 changes: 0 additions & 83 deletions .k8s/staging/deployment.yml

This file was deleted.

46 changes: 46 additions & 0 deletions .k8s/staging/jobs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apiVersion: batch/v1
kind: Job
metadata:
namespace: louper-staging
name: github-ci
generatedName: build-image-and-push-
annotations:
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/hook-delete-policy: HookSucceeded
spec:
template:
spec:
containers:
- name: github-ci
image: pkgxdev/pkgx:latest
imagePullPolicy: Always
env:
- name: GITHUB_TOKEN
valueFrom:
secretKeyRef:
name: gh
key: token
command:
- /bin/bash
- -c
- |
apt update && apt install -y ca-certificates
pkgx install gh
pkgx install jq
pkgx install uuidgen
gh auth login
export JOB_ID=$(uuidgen)
echo "{\"job_id\": \"$JOB_ID\" }" | gh workflow run build-and-deploy-staging --repo mark3labs/louper-v3 --ref dev --json
STATUS="starting"
while [[ "$STATUS" != "completed" && "$STATUS" != "failure" ]]
do
STATUS=$(gh run list --workflow=build-and-deploy-staging --repo mark3labs/louper-v3 --json "status,name" | jq --arg i "build-and-deploy-staging:$JOB_ID" '.[] | select(.name == $i)' | jq -r '.status')
echo "Job Status: $STATUS"
sleep 1
done
resources:
limits:
cpu: 1
memory: 1Gi
restartPolicy: Never
Loading

0 comments on commit 1cde2a7

Please sign in to comment.