release
This commit is contained in:
parent
0e17390973
commit
8e87cfed5b
112
.github/workflows/cicd.yaml
vendored
112
.github/workflows/cicd.yaml
vendored
@ -2,29 +2,24 @@ name: Frontend CI/CD Pipeline
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches: [ main ]
|
||||||
- main
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
REGISTRY: dg0200cr.azurecr.io
|
PROJECT_FOLDER: "."
|
||||||
IMAGE_ORG: lifesub
|
BUILD_FOLDER: "deployment"
|
||||||
APP_NAME: lifesub-web
|
|
||||||
NAMESPACE: dg0200-lifesub-web-ns
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
# Build stage
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
|
||||||
image_tag: ${{ steps.set-image-tag.outputs.image_tag }}
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Node.js
|
- name: Set up Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '20'
|
node-version: '20'
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
@ -37,57 +32,71 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: build-files
|
name: build-files
|
||||||
path: build/
|
path: build/
|
||||||
|
retention-days: 1
|
||||||
- name: Generate image tag
|
|
||||||
id: set-image-tag
|
|
||||||
run: |
|
|
||||||
timestamp=$(date '+%Y%m%d%H%M%S')
|
|
||||||
echo "image_tag=${timestamp}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
|
# Release stage
|
||||||
release:
|
release:
|
||||||
needs: build
|
needs: build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
image_tag: ${{ steps.set-tag.outputs.tag }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
- name: Load environment variables
|
||||||
|
run: |
|
||||||
|
props=$(cat deployment/deploy_env_vars)
|
||||||
|
echo "$props" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Set image tag
|
||||||
|
id: set-tag
|
||||||
|
run: |
|
||||||
|
timestamp=$(date +'%Y%m%d%H%M%S')
|
||||||
|
echo "tag=${timestamp}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Download build artifact
|
- name: Download build artifact
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: build-files
|
name: build-files
|
||||||
path: build
|
path: build/
|
||||||
|
|
||||||
- name: Login to Azure Container Registry
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Log in to Azure Container Registry
|
||||||
uses: azure/docker-login@v1
|
uses: azure/docker-login@v1
|
||||||
with:
|
with:
|
||||||
login-server: ${{ env.REGISTRY }}
|
login-server: ${{ env.registry }}
|
||||||
username: ${{ secrets.ACR_USERNAME }}
|
username: ${{ secrets.ACR_USERNAME }}
|
||||||
password: ${{ secrets.ACR_PASSWORD }}
|
password: ${{ secrets.ACR_PASSWORD }}
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push image
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: deployment/Dockerfile-lifesub-web
|
file: deployment/Dockerfile-lifesub-web
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/${{ env.APP_NAME }}:${{ needs.build.outputs.image_tag }}
|
tags: ${{ env.registry }}/${{ env.image_org }}/lifesub-web:${{ steps.set-tag.outputs.tag }}
|
||||||
build-args: |
|
build-args: |
|
||||||
PROJECT_FOLDER=.
|
PROJECT_FOLDER=${{ env.PROJECT_FOLDER }}
|
||||||
REACT_APP_MEMBER_URL=http://20.249.185.127/member
|
BUILD_FOLDER=${{ env.BUILD_FOLDER }}
|
||||||
REACT_APP_MYSUB_URL=http://20.249.185.127/mysub
|
EXPORT_PORT=${{ env.export_port }}
|
||||||
REACT_APP_RECOMMEND_URL=http://20.249.185.127/recommend
|
REACT_APP_MEMBER_URL=${{ env.react_app_member_url }}
|
||||||
BUILD_FOLDER=deployment
|
REACT_APP_MYSUB_URL=${{ env.react_app_mysub_url }}
|
||||||
EXPORT_PORT=18080
|
REACT_APP_RECOMMEND_URL=${{ env.react_app_recommend_url }}
|
||||||
|
|
||||||
|
# Deploy stage
|
||||||
deploy:
|
deploy:
|
||||||
needs: [build, release]
|
needs: release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
- name: Load environment variables
|
||||||
|
run: |
|
||||||
|
props=$(cat deployment/deploy_env_vars)
|
||||||
|
echo "$props" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Azure login
|
- name: Azure login
|
||||||
uses: azure/login@v1
|
uses: azure/login@v1
|
||||||
with:
|
with:
|
||||||
@ -97,22 +106,22 @@ jobs:
|
|||||||
uses: azure/aks-set-context@v3
|
uses: azure/aks-set-context@v3
|
||||||
with:
|
with:
|
||||||
resource-group: ictcoe-edu
|
resource-group: ictcoe-edu
|
||||||
cluster-name: dg0200-aks
|
cluster-name: ${{ env.teamid }}-aks
|
||||||
|
|
||||||
- name: Create namespace if not exists
|
- name: Create namespace
|
||||||
run: |
|
run: |
|
||||||
kubectl create namespace ${{ env.NAMESPACE }} --dry-run=client -o yaml | kubectl apply -f -
|
kubectl create namespace ${{ env.teamid }}-${{ env.root_project }}-ns --dry-run=client -o yaml | kubectl apply -f -
|
||||||
|
|
||||||
- name: Generate deployment manifest
|
- name: Generate deployment manifest
|
||||||
run: |
|
run: |
|
||||||
export namespace=${{ env.NAMESPACE }}
|
export namespace=${{ env.teamid }}-${{ env.root_project }}-ns
|
||||||
export lifesub_web_image_path=${{ env.REGISTRY }}/${{ env.IMAGE_ORG }}/${{ env.APP_NAME }}:${{ needs.build.outputs.image_tag }}
|
export lifesub_web_image_path=${{ env.registry }}/${{ env.image_org }}/lifesub-web:${{ needs.release.outputs.image_tag }}
|
||||||
export replicas=1
|
export replicas=${{ env.replicas }}
|
||||||
export export_port=18080
|
export export_port=${{ env.export_port }}
|
||||||
export resources_requests_cpu=256m
|
export resources_requests_cpu=${{ env.resources_requests_cpu }}
|
||||||
export resources_requests_memory=256Mi
|
export resources_requests_memory=${{ env.resources_requests_memory }}
|
||||||
export resources_limits_cpu=1024m
|
export resources_limits_cpu=${{ env.resources_limits_cpu }}
|
||||||
export resources_limits_memory=1024Mi
|
export resources_limits_memory=${{ env.resources_limits_memory }}
|
||||||
|
|
||||||
envsubst < deployment/deploy.yaml.template > deployment/deploy.yaml
|
envsubst < deployment/deploy.yaml.template > deployment/deploy.yaml
|
||||||
echo "Generated manifest:"
|
echo "Generated manifest:"
|
||||||
@ -121,10 +130,11 @@ jobs:
|
|||||||
- name: Deploy to AKS
|
- name: Deploy to AKS
|
||||||
run: |
|
run: |
|
||||||
kubectl apply -f deployment/deploy.yaml
|
kubectl apply -f deployment/deploy.yaml
|
||||||
kubectl -n ${{ env.NAMESPACE }} wait --for=condition=available deployment/lifesub-web --timeout=300s
|
echo "Waiting for deployment to be ready..."
|
||||||
|
kubectl -n ${{ env.teamid }}-${{ env.root_project }}-ns wait --for=condition=available deployment/lifesub-web --timeout=300s
|
||||||
|
|
||||||
echo "Waiting for service external IP..."
|
echo "Waiting for service external IP..."
|
||||||
while [[ -z $(kubectl -n ${{ env.NAMESPACE }} get svc lifesub-web -o jsonpath='{.status.loadBalancer.ingress[0].ip}') ]]; do
|
while [[ -z $(kubectl -n ${{ env.teamid }}-${{ env.root_project }}-ns get svc lifesub-web -o jsonpath='{.status.loadBalancer.ingress[0].ip}') ]]; do
|
||||||
sleep 5
|
sleep 5
|
||||||
done
|
done
|
||||||
echo "Service external IP: $(kubectl -n ${{ env.NAMESPACE }} get svc lifesub-web -o jsonpath='{.status.loadBalancer.ingress[0].ip}')"
|
echo "Service external IP: $(kubectl -n ${{ env.teamid }}-${{ env.root_project }}-ns get svc lifesub-web -o jsonpath='{.status.loadBalancer.ingress[0].ip}')"
|
||||||
Loading…
x
Reference in New Issue
Block a user