mirror of
https://github.com/cna-bootcamp/lifesub.git
synced 2025-12-06 16:16:22 +00:00
add cicd
This commit is contained in:
parent
1148a95188
commit
87333469d2
151
.github/workflows/cicd.yaml
vendored
151
.github/workflows/cicd.yaml
vendored
@ -2,58 +2,36 @@ name: Backend CI/CD Pipeline
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "k8s" ]
|
branches:
|
||||||
pull_request:
|
- k8s
|
||||||
branches: [ "k8s" ]
|
|
||||||
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
# Team Settings
|
REGISTRY: ${{ vars.REGISTRY || 'dg0200cr.azurecr.io' }}
|
||||||
TEAMID: dg0200
|
IMAGE_ORG: ${{ vars.IMAGE_ORG || 'lifesub' }}
|
||||||
ROOT_PROJECT: lifesub
|
|
||||||
|
|
||||||
# Container Registry Settings
|
|
||||||
REGISTRY: dg0200cr.azurecr.io
|
|
||||||
IMAGE_ORG: lifesub
|
|
||||||
|
|
||||||
# Application Settings
|
|
||||||
REPLICAS: 2
|
|
||||||
ALLOWED_ORIGINS: http://20.249.193.161
|
|
||||||
|
|
||||||
# Security Settings
|
|
||||||
JWT_SECRET_KEY: 8O2HQ13etL2BWZvYOiWsJ5uWFoLi6NBUG8divYVoCgtHVvlk3dqRksMl16toztDUeBTSIuOOPvHIrYq11G2BwQ
|
|
||||||
POSTGRES_USER: admin
|
|
||||||
POSTGRES_PASSWORD: Passw0rd
|
|
||||||
|
|
||||||
# Resource Settings
|
|
||||||
RESOURCES_REQUESTS_CPU: 256m
|
|
||||||
RESOURCES_REQUESTS_MEMORY: 256Mi
|
|
||||||
RESOURCES_LIMITS_CPU: 1024m
|
|
||||||
RESOURCES_LIMITS_MEMORY: 1024Mi
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Set up JDK 21
|
steps:
|
||||||
uses: actions/setup-java@v3
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up JDK
|
||||||
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
cache: gradle
|
|
||||||
|
|
||||||
- name: Setup Gradle
|
- name: Setup Gradle
|
||||||
uses: gradle/gradle-build-action@v2
|
uses: gradle/gradle-build-action@v3
|
||||||
|
|
||||||
- name: Build with Gradle
|
- name: Build applications
|
||||||
run: |
|
run: |
|
||||||
chmod +x gradlew
|
chmod +x gradlew
|
||||||
./gradlew clean :member:build :mysub-infra:build :recommend:build
|
./gradlew clean :member:build :mysub-infra:build :recommend:build
|
||||||
|
|
||||||
- name: Upload build artifacts
|
- name: Upload build artifacts
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: build-artifacts
|
name: build-artifacts
|
||||||
path: |
|
path: |
|
||||||
@ -65,19 +43,19 @@ jobs:
|
|||||||
needs: build
|
needs: build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
image_tag: ${{ steps.set-image-tag.outputs.image_tag }}
|
image_tag: ${{ steps.set-tag.outputs.tag }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Download build artifacts
|
- name: Download build artifacts
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: build-artifacts
|
name: build-artifacts
|
||||||
|
|
||||||
- name: Set image tag
|
- name: Set timestamp for image tag
|
||||||
id: set-image-tag
|
id: set-tag
|
||||||
run: |
|
run: echo "tag=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
|
||||||
echo "image_tag=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Login to Azure Container Registry
|
- name: Login to Azure Container Registry
|
||||||
uses: azure/docker-login@v1
|
uses: azure/docker-login@v1
|
||||||
@ -88,78 +66,59 @@ jobs:
|
|||||||
|
|
||||||
- name: Build and push images
|
- name: Build and push images
|
||||||
run: |
|
run: |
|
||||||
IMAGE_TAG=${{ steps.set-image-tag.outputs.image_tag }}
|
for service in member mysub recommend; do
|
||||||
|
build_dir=$([[ "$service" == "mysub" ]] && echo "mysub-infra" || echo "$service")
|
||||||
|
jar_file=$([[ "$service" == "mysub" ]] && echo "mysub.jar" || echo "${service}.jar")
|
||||||
|
|
||||||
# Build and push member service
|
docker build \
|
||||||
docker build \
|
--build-arg BUILD_LIB_DIR="${build_dir}/build/libs" \
|
||||||
--build-arg BUILD_LIB_DIR="member/build/libs" \
|
--build-arg ARTIFACTORY_FILE="${jar_file}" \
|
||||||
--build-arg ARTIFACTORY_FILE="member.jar" \
|
-f deployment/Dockerfile \
|
||||||
-f deployment/Dockerfile \
|
-t ${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/${service}:${{ steps.set-tag.outputs.tag }} .
|
||||||
-t ${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/member:${IMAGE_TAG} .
|
|
||||||
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/member:${IMAGE_TAG}
|
|
||||||
|
|
||||||
# Build and push mysub service
|
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/${service}:${{ steps.set-tag.outputs.tag }}
|
||||||
docker build \
|
done
|
||||||
--build-arg BUILD_LIB_DIR="mysub-infra/build/libs" \
|
|
||||||
--build-arg ARTIFACTORY_FILE="mysub.jar" \
|
|
||||||
-f deployment/Dockerfile \
|
|
||||||
-t ${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/mysub:${IMAGE_TAG} .
|
|
||||||
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/mysub:${IMAGE_TAG}
|
|
||||||
|
|
||||||
# Build and push recommend service
|
|
||||||
docker build \
|
|
||||||
--build-arg BUILD_LIB_DIR="recommend/build/libs" \
|
|
||||||
--build-arg ARTIFACTORY_FILE="recommend.jar" \
|
|
||||||
-f deployment/Dockerfile \
|
|
||||||
-t ${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/recommend:${IMAGE_TAG} .
|
|
||||||
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/recommend:${IMAGE_TAG}
|
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
needs: release
|
needs: release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Azure Login
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Azure login
|
||||||
uses: azure/login@v1
|
uses: azure/login@v1
|
||||||
with:
|
with:
|
||||||
creds: ${{ secrets.AZURE_CREDENTIALS }}
|
creds: ${{ secrets.AZURE_CREDENTIALS }}
|
||||||
|
|
||||||
- name: Set AKS Context
|
- name: Set AKS context
|
||||||
uses: azure/aks-set-context@v3
|
uses: azure/aks-set-context@v3
|
||||||
with:
|
with:
|
||||||
resource-group: ictcoe-edu
|
resource-group: ictcoe-edu
|
||||||
cluster-name: ${{ env.TEAMID }}-aks
|
cluster-name: dg0200-aks
|
||||||
|
|
||||||
|
- name: Load environment variables
|
||||||
|
run: source deployment/deploy_env_vars
|
||||||
|
|
||||||
- name: Generate manifest
|
- name: Generate manifest
|
||||||
env:
|
|
||||||
IMAGE_TAG: ${{ needs.release.outputs.image_tag }}
|
|
||||||
NAMESPACE: ${{ env.TEAMID }}-${{ env.ROOT_PROJECT }}-ns
|
|
||||||
run: |
|
run: |
|
||||||
# Create namespace if not exists
|
export namespace=dg0200-lifesub-ns
|
||||||
kubectl create namespace ${NAMESPACE} --dry-run=client -o yaml | kubectl apply -f -
|
export allowed_origins=http://20.249.193.161
|
||||||
|
export jwt_secret_key=${{ secrets.JWT_SECRET_KEY }}
|
||||||
|
export postgres_user=${{ secrets.POSTGRES_USER }}
|
||||||
|
export postgres_password=${{ secrets.POSTGRES_PASSWORD }}
|
||||||
|
export replicas=2
|
||||||
|
export resources_requests_cpu=256m
|
||||||
|
export resources_requests_memory=256Mi
|
||||||
|
export resources_limits_cpu=1024m
|
||||||
|
export resources_limits_memory=1024Mi
|
||||||
|
|
||||||
# Set environment variables for envsubst
|
# Set image paths with tag from release job
|
||||||
export namespace=${NAMESPACE}
|
export member_image_path=${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/member:${{ needs.release.outputs.image_tag }}
|
||||||
export allowed_origins=${{ env.ALLOWED_ORIGINS }}
|
export mysub_image_path=${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/mysub:${{ needs.release.outputs.image_tag }}
|
||||||
export jwt_secret_key=${{ env.JWT_SECRET_KEY }}
|
export recommend_image_path=${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/recommend:${{ needs.release.outputs.image_tag }}
|
||||||
export postgres_user=${{ env.POSTGRES_USER }}
|
|
||||||
export postgres_password=${{ env.POSTGRES_PASSWORD }}
|
|
||||||
export replicas=${{ env.REPLICAS }}
|
|
||||||
export resources_requests_cpu=${{ env.RESOURCES_REQUESTS_CPU }}
|
|
||||||
export resources_requests_memory=${{ env.RESOURCES_REQUESTS_MEMORY }}
|
|
||||||
export resources_limits_cpu=${{ env.RESOURCES_LIMITS_CPU }}
|
|
||||||
export resources_limits_memory=${{ env.RESOURCES_LIMITS_MEMORY }}
|
|
||||||
|
|
||||||
# Set image paths
|
|
||||||
export member_image_path=${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/member:${IMAGE_TAG}
|
|
||||||
export mysub_image_path=${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/mysub:${IMAGE_TAG}
|
|
||||||
export recommend_image_path=${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/recommend:${IMAGE_TAG}
|
|
||||||
|
|
||||||
# Generate manifest
|
|
||||||
envsubst < deployment/deploy.yaml.template > deployment/deploy.yaml
|
envsubst < deployment/deploy.yaml.template > deployment/deploy.yaml
|
||||||
|
|
||||||
# Debug: Print generated manifest
|
|
||||||
cat deployment/deploy.yaml
|
cat deployment/deploy.yaml
|
||||||
|
|
||||||
- name: Deploy to AKS
|
- name: Deploy to AKS
|
||||||
@ -167,6 +126,6 @@ jobs:
|
|||||||
kubectl apply -f deployment/deploy.yaml
|
kubectl apply -f deployment/deploy.yaml
|
||||||
|
|
||||||
echo "Waiting for deployments to be ready..."
|
echo "Waiting for deployments to be ready..."
|
||||||
kubectl -n ${{ env.TEAMID }}-${{ env.ROOT_PROJECT }}-ns wait --for=condition=available deployment/member --timeout=300s
|
kubectl -n dg0200-lifesub-ns wait --for=condition=available deployment/member --timeout=300s
|
||||||
kubectl -n ${{ env.TEAMID }}-${{ env.ROOT_PROJECT }}-ns wait --for=condition=available deployment/mysub --timeout=300s
|
kubectl -n dg0200-lifesub-ns wait --for=condition=available deployment/mysub --timeout=300s
|
||||||
kubectl -n ${{ env.TEAMID }}-${{ env.ROOT_PROJECT }}-ns wait --for=condition=available deployment/recommend --timeout=300s
|
kubectl -n dg0200-lifesub-ns wait --for=condition=available deployment/recommend --timeout=300s
|
||||||
Loading…
x
Reference in New Issue
Block a user