mirror of
https://github.com/cna-bootcamp/lifesub.git
synced 2025-12-06 16:16:22 +00:00
131 lines
4.2 KiB
YAML
131 lines
4.2 KiB
YAML
name: Backend CI/CD Pipeline
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- k8s
|
|
|
|
env:
|
|
REGISTRY: ${{ vars.REGISTRY || 'dg0200cr.azurecr.io' }}
|
|
IMAGE_ORG: ${{ vars.IMAGE_ORG || 'lifesub' }}
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Set up JDK
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
java-version: '21'
|
|
distribution: 'temurin'
|
|
|
|
- name: Setup Gradle
|
|
uses: gradle/gradle-build-action@v3
|
|
|
|
- name: Build applications
|
|
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
|
|
mysub-infra/build/libs
|
|
recommend/build/libs
|
|
|
|
release:
|
|
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: Set timestamp for image tag
|
|
id: set-tag
|
|
run: echo "tag=$(date +'%Y%m%d%H%M%S')" >> $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 ${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/${service}:${{ steps.set-tag.outputs.tag }} .
|
|
|
|
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/${service}:${{ steps.set-tag.outputs.tag }}
|
|
done
|
|
|
|
deploy:
|
|
needs: release
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Azure login
|
|
uses: azure/login@v1
|
|
with:
|
|
creds: ${{ secrets.AZURE_CREDENTIALS }}
|
|
|
|
- name: Set AKS context
|
|
uses: azure/aks-set-context@v3
|
|
with:
|
|
resource-group: ictcoe-edu
|
|
cluster-name: dg0200-aks
|
|
|
|
- name: Load environment variables
|
|
run: source deployment/deploy_env_vars
|
|
|
|
- name: Generate manifest
|
|
run: |
|
|
export namespace=dg0200-lifesub-ns
|
|
export allowed_origins=http://4.230.156.229
|
|
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 image paths with tag from release job
|
|
export member_image_path=${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/member:${{ needs.release.outputs.image_tag }}
|
|
export mysub_image_path=${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/mysub:${{ needs.release.outputs.image_tag }}
|
|
export recommend_image_path=${{ env.REGISTRY }}/${{ env.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 dg0200-lifesub-ns wait --for=condition=available deployment/member --timeout=300s
|
|
kubectl -n dg0200-lifesub-ns wait --for=condition=available deployment/mysub --timeout=300s
|
|
kubectl -n dg0200-lifesub-ns wait --for=condition=available deployment/recommend --timeout=300s |