Skip to content

feat: Implement Collaboration Service #66

feat: Implement Collaboration Service

feat: Implement Collaboration Service #66

Workflow file for this run

# References https://docs.docker.com/build/ci/github-actions/
# https://stackoverflow.com/questions/77740410/github-docker-build-push-action-with-multiple-architectures-is-slow
# https://dlmade.medium.com/ci-cd-with-github-action-and-aws-eks-5fd9714010cd
name: 'Staging Environment CI/CD Pipeline'
on:
push:
branches:
- frontend-staging
- staging
pull_request:
branches:
- frontend-staging
- staging
workflow_dispatch:
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node: [20, 22]
name: Run Tests on ${{ matrix.os }} with Node ${{ matrix.node }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Codebase
uses: actions/checkout@v4
- name: Setup Node ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Install Frontend Node Dependencies
working-directory: peer-prep
run: npm ci
- name: Test Build on Frontend
working-directory: peer-prep
run: npm run build
build:
# build container for both x86 and arm platforms
needs: test
environment: staging
name: Build Staging Containers and Push to Docker Hub
runs-on: ubuntu-latest
strategy:
matrix:
arch: [amd64, arm64]
steps:
- name: Checkout Codebase
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build User Service Image
uses: docker/build-push-action@v6
with:
context: ./user-service
file: ./user-service/Dockerfile
push: true
platforms: linux/${{ matrix.arch }}
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/peerprep-user-service:staging-${{ vars.DOCKER_IMAGE_VERSION }}
${{ secrets.DOCKERHUB_USERNAME }}/peerprep-user-service:staging-${{ github.sha }}
- name: Build Question Service Image
uses: docker/build-push-action@v6
with:
context: ./question-service
file: ./question-service/Dockerfile
push: true
platforms: linux/${{ matrix.arch }}
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/peerprep-question-service:staging-${{ vars.DOCKER_IMAGE_VERSION }}
${{ secrets.DOCKERHUB_USERNAME }}/peerprep-question-service:staging-${{ github.sha }}
- name: Build Matching Service Image
uses: docker/build-push-action@v6
with:
context: ./matching-service
file: ./matching-service/Dockerfile
push: true
platforms: linux/${{ matrix.arch }}
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/peerprep-matching-service:staging-${{ vars.DOCKER_IMAGE_VERSION }}
${{ secrets.DOCKERHUB_USERNAME }}/peerprep-matching-service:staging-${{ github.sha }}
- name: Build Collaboration Service Image
uses: docker/build-push-action@v6
with:
context: ./collaboration-service
file: ./collaboration-service/Dockerfile
push: true
platforms: linux/${{ matrix.arch }}
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/peerprep-collaboration-service:staging-${{ vars.DOCKER_IMAGE_VERSION }}
${{ secrets.DOCKERHUB_USERNAME }}/peerprep-collaboration-service:staging-${{ github.sha }}
deploy:
needs: build
environment: staging
name: Deploy Staging Environment
runs-on: ubuntu-latest
steps:
- name: Checkout Codebase
uses: actions/checkout@v4
- name: Setup Node 20
uses: actions/setup-node@v4
with:
node-version: 20
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
# Frontend Deployment to S3
- name: Copy Frontend Secrets into Build Folder
working-directory: peer-prep
shell: bash
env:
FRONTEND_SECRETS: ${{ secrets.FRONTEND_SECRETS }}
run: 'echo "$FRONTEND_SECRETS" | base64 --decode > .env'
- name: Build and Deploy Frontend on S3
working-directory: peer-prep
run: |
npm i
npm run build
- name: Upload to S3
working-directory: peer-prep/dist
run: |
aws s3 sync . s3://peerprep
- name: Retrieve S3 Bucket URL
run: echo "http://peerprep.s3-website-ap-southeast-1.amazonaws.com/"
# Backend Deployment to EKS
- name: Get EKS kubectl Configs
run: aws eks update-kubeconfig --region ${{ secrets.AWS_REGION }} --name ${{ secrets.EKS_CLUSTER_NAME }}
# echo out string into file taken from
# https://stackoverflow.com/questions/59481933/how-can-i-extract-secrets-using-github-actions
- name: Create Secrets File
working-directory: kubernetes
shell: bash
env:
K8S_SECRETS: ${{ secrets.KUBERNETES_SECRETS }}
run: 'echo "$KUBERNETES_SECRETS" | base64 --decode > 1-Kubernetes-Secrets.yml'
# kubectl apply the YML files to do a deployment
- name: Apply Secrets YML File to EKS Cluster
working-directory: kubernetes
run: kubectl apply -f 1-Kubernetes-Secrets.yml
- name: Apply Services YML File to EKS Cluster
working-directory: kubernetes
run: kubectl apply -f 2-PeerPrep-Services.yml
# replaces the placeholder text with the actual image
- name: Run sed on Compute Infrastructure YML File
working-directory: kubernetes
run: sed -i 's/IMAGE_TAG/staging-${{ vars.DOCKER_IMAGE_VERSION }}/' 3-PeerPrep-Staging-Compute-Infrastructure.yml
- name: Apply Compute Infrastructure YML File
working-directory: kubernetes
run: kubectl apply -f 3-PeerPrep-Compute-Infrastructure.yml
- name: Apply Ingress YML File to EKS Cluster
working-directory: kubernetes
run: kubectl apply -f 4-PeerPrep-Ingress.yml
- name: Restart Deployment to Force Redeployment of Containers in EKS Cluster
working-directory: kubernetes
run: kubectl rollout restart deployment ${{ secrets.EKS_CLUSTER_NAME }}
# Deploy changes to API Gateway
- name: Deploy Changes to API Gateway v1 Stage
run: |
aws apigatewayv2 create-deployment --api-id ${{ secrets.AWS_API_GATEWAY_ID }} --stage-name staging