mirror of
https://github.com/cna-bootcamp/lifesub.git
synced 2025-12-06 16:16:22 +00:00
143 lines
4.6 KiB
YAML
143 lines
4.6 KiB
YAML
name: Backend CI/CD Pipeline
|
|
|
|
# Temporarily disabled
|
|
# on:
|
|
# push:
|
|
# branches: [ k8s ]
|
|
|
|
env:
|
|
JAVA_VERSION: '21'
|
|
GRADLE_VERSION: '8.5'
|
|
|
|
jobs:
|
|
build:
|
|
name: Build Applications
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Set up JDK
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
java-version: ${{ env.JAVA_VERSION }}
|
|
distribution: 'temurin'
|
|
|
|
- name: Setup Gradle
|
|
uses: gradle/gradle-build-action@v2
|
|
with:
|
|
gradle-version: ${{ env.GRADLE_VERSION }}
|
|
|
|
- name: Build with Gradle
|
|
run: |
|
|
chmod +x gradlew
|
|
./gradlew clean :member:build :mysub-infra:build :recommend:build
|
|
|
|
- name: Upload Build Artifacts
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: build-artifacts
|
|
path: |
|
|
member/build/libs/*.jar
|
|
mysub-infra/build/libs/*.jar
|
|
recommend/build/libs/*.jar
|
|
|
|
release:
|
|
name: Build and Push Images
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
image_tag: ${{ steps.set_tag.outputs.tag }}
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Download Build Artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: build-artifacts
|
|
|
|
- name: Load Environment Variables
|
|
run: source deployment/deploy_env_vars
|
|
|
|
- name: Generate Image Tag
|
|
id: set_tag
|
|
run: |
|
|
tag=$(date +'%Y%m%d%H%M%S')
|
|
echo "tag=${tag}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Login to Azure Container Registry
|
|
uses: azure/docker-login@v1
|
|
with:
|
|
login-server: ${{ env.registry }}
|
|
username: ${{ secrets.ACR_USERNAME }}
|
|
password: ${{ secrets.ACR_PASSWORD }}
|
|
|
|
- name: Build and Push Images
|
|
run: |
|
|
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")
|
|
|
|
docker build \
|
|
--build-arg BUILD_LIB_DIR="${build_dir}/build/libs" \
|
|
--build-arg ARTIFACTORY_FILE="${jar_file}" \
|
|
-f deployment/Dockerfile \
|
|
-t ${registry}/${image_org}/${service}:${{ steps.set_tag.outputs.tag }} .
|
|
|
|
docker push ${registry}/${image_org}/${service}:${{ steps.set_tag.outputs.tag }}
|
|
done
|
|
|
|
deploy:
|
|
name: Deploy to AKS
|
|
needs: release
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Load Environment Variables
|
|
run: source deployment/deploy_env_vars
|
|
|
|
- name: Azure Login
|
|
uses: azure/login@v1
|
|
with:
|
|
creds: ${{ secrets.AZURE_CREDENTIALS }}
|
|
|
|
- name: Set AKS Context
|
|
uses: azure/aks-set-context@v1
|
|
with:
|
|
resource-group: ictcoe-edu
|
|
cluster-name: ${{ env.teamid }}-aks
|
|
|
|
- name: Create Namespace
|
|
run: |
|
|
kubectl create namespace ${teamid}-${root_project}-ns --dry-run=client -o yaml | kubectl apply -f -
|
|
|
|
- name: Generate Manifest
|
|
run: |
|
|
export namespace=${teamid}-${root_project}-ns
|
|
export allowed_origins=${allowed_origins}
|
|
export jwt_secret_key=${jwt_secret_key}
|
|
export postgres_user=${postgres_user}
|
|
export postgres_password=${postgres_password}
|
|
export replicas=${replicas}
|
|
export resources_requests_cpu=${resources_requests_cpu}
|
|
export resources_requests_memory=${resources_requests_memory}
|
|
export resources_limits_cpu=${resources_limits_cpu}
|
|
export resources_limits_memory=${resources_limits_memory}
|
|
export member_image_path=${registry}/${image_org}/member:${{ needs.release.outputs.image_tag }}
|
|
export mysub_image_path=${registry}/${image_org}/mysub:${{ needs.release.outputs.image_tag }}
|
|
export recommend_image_path=${registry}/${image_org}/recommend:${{ needs.release.outputs.image_tag }}
|
|
|
|
envsubst < deployment/deploy.yaml.template > deployment/deploy.yaml
|
|
cat deployment/deploy.yaml
|
|
|
|
- name: Deploy to AKS
|
|
run: |
|
|
kubectl apply -f deployment/deploy.yaml
|
|
|
|
echo "Waiting for deployments to be ready..."
|
|
kubectl -n ${namespace} wait --for=condition=available deployment/member --timeout=300s
|
|
kubectl -n ${namespace} wait --for=condition=available deployment/mysub --timeout=300s
|
|
kubectl -n ${namespace} wait --for=condition=available deployment/recommend --timeout=300s |