docs: add deployment playbooks and templates
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
name: Build and Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install kubectl
|
||||
run: |
|
||||
ARCH=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
|
||||
curl -sLO "https://dl.k8s.io/release/v1.35.0/bin/linux/${ARCH}/kubectl"
|
||||
chmod +x kubectl
|
||||
mv kubectl /usr/local/bin/kubectl
|
||||
|
||||
- name: Configure kubectl
|
||||
run: |
|
||||
kubectl config set-cluster cluster --server=${{ secrets.K8S_API_SERVER }} --insecure-skip-tls-verify=true
|
||||
kubectl config set-credentials ci-deployer --token=${{ secrets.K8S_SA_TOKEN }}
|
||||
kubectl config set-context cluster --cluster=cluster --user=ci-deployer --namespace=#NAMESPACE
|
||||
kubectl config use-context cluster
|
||||
|
||||
- name: Restore env from secret
|
||||
run: |
|
||||
kubectl get secret #SECRET_NAME -n #NAMESPACE \
|
||||
-o go-template='{{range $k,$v := .data}}{{$k}}={{$v|base64decode}}{{"\n"}}{{end}}' > .env
|
||||
|
||||
- name: Build images
|
||||
run: |
|
||||
TAG=${{ gitea.sha }}
|
||||
docker build -t #IMAGE:frontend-$TAG -t #IMAGE:frontend .
|
||||
docker build --target migration -t #IMAGE:migration .
|
||||
|
||||
- name: Push images
|
||||
run: |
|
||||
TAG=${{ gitea.sha }}
|
||||
docker push #IMAGE:frontend-$TAG
|
||||
docker push #IMAGE:frontend
|
||||
docker push #IMAGE:migration
|
||||
|
||||
- name: Run migration and roll out
|
||||
run: |
|
||||
TAG=${{ gitea.sha }}
|
||||
kubectl delete job #APP_NAME-migrate -n #NAMESPACE --ignore-not-found
|
||||
kubectl create job #APP_NAME-migrate --image=#IMAGE:migration -n #NAMESPACE --dry-run=client -o json -- bun drizzle-kit push | \
|
||||
jq '.spec.template.spec.containers[0].envFrom = [{"secretRef": {"name": "#SECRET_NAME"}}]' | kubectl apply -f -
|
||||
kubectl set image deployment/#APP_NAME #APP_NAME=#IMAGE:frontend-$TAG -n #NAMESPACE
|
||||
kubectl wait --for=condition=complete job/#APP_NAME-migrate -n #NAMESPACE --timeout=600s
|
||||
kubectl rollout status deployment/#APP_NAME -n #NAMESPACE --timeout=180s
|
||||
Reference in New Issue
Block a user