feat: implements a better kubernetes deployment setup
This commit is contained in:
108
.github/workflows/deploy.yml
vendored
Normal file
108
.github/workflows/deploy.yml
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: 'Tag to deploy'
|
||||
required: false
|
||||
default: 'latest'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [22.12.0]
|
||||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
cache: "npm"
|
||||
- run: npm install
|
||||
- run: npm run build --if-present
|
||||
|
||||
docker:
|
||||
needs: [build]
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write # required to push to ghcr.io
|
||||
id-token: write # optional for OIDC if you use it
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
|
||||
- name: Log in to GHCR
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Prepare image tags
|
||||
run: |
|
||||
OWNER=$(echo "${GITHUB_REPOSITORY_OWNER}" | tr '[:upper:]' '[:lower:]')
|
||||
REPO=$(echo "${GITHUB_REPOSITORY#*/}" | tr '[:upper:]' '[:lower:]')
|
||||
|
||||
# Determine tag
|
||||
if [ "${GITHUB_REF_NAME}" = "main" ]; then
|
||||
TAG="latest"
|
||||
else
|
||||
TAG="dev"
|
||||
fi
|
||||
|
||||
SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
|
||||
IMAGE_BASE="ghcr.io/${OWNER}/${REPO}"
|
||||
|
||||
echo "IMAGE_LATEST=${IMAGE_BASE}:${TAG}" >> $GITHUB_ENV
|
||||
echo "IMAGE_SHA=${IMAGE_BASE}:sha-${SHORT_SHA}" >> $GITHUB_ENV
|
||||
|
||||
- name: Build Docker image
|
||||
run: |
|
||||
docker build -t $IMAGE_LATEST -t $IMAGE_SHA .
|
||||
|
||||
- name: Push Docker images
|
||||
run: |
|
||||
docker push $IMAGE_LATEST
|
||||
docker push $IMAGE_SHA
|
||||
|
||||
deploy:
|
||||
needs: [docker]
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name == 'push' && (github.ref == 'refs/heads/main')
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Kubeconfig
|
||||
uses: azure/setup-kubectl@v3
|
||||
with:
|
||||
method: kubeconfig
|
||||
kubeconfig: ${{ secrets.PORTFOLIO_KUBECONFIG }}
|
||||
|
||||
- name: Deploy to Kubernetes
|
||||
run: |
|
||||
OWNER=$(echo "${GITHUB_REPOSITORY_OWNER}" | tr '[:upper:]' '[:lower:]')
|
||||
REPO=$(echo "${GITHUB_REPOSITORY#*/}" | tr '[:upper:]' '[:lower:]')
|
||||
|
||||
IMAGE_BASE="ghcr.io/${OWNER}/${REPO}"
|
||||
TAG="${{ github.event.inputs.tag || 'latest' }}"
|
||||
|
||||
kubectl config set-context --current --namespace=$KUBE_NAMESPACE
|
||||
|
||||
# Apply any other configuration changes if needed
|
||||
envsubst < .k8s/config.yml | kubectl apply -f -
|
||||
envsubst < .k8s/deployment.yaml | kubectl apply -f -
|
||||
envsubst < .k8s/service.yaml | kubectl apply -f -
|
||||
envsubst < .k8s/ingress.yaml | kubectl apply -f -
|
||||
Reference in New Issue
Block a user