Debug #26
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master | |
env: | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
jobs: | |
ECR_Region: | |
runs-on: ubuntu-latest | |
outputs: | |
aws_region: ${{steps.step1.outputs.aws_region}} | |
steps: | |
- name: Print inputs passed to the reusable workflow | |
id: step1 | |
run: | | |
echo "::set-output name=aws_region::$AWS_REGION" | |
echo "aws_region: $AWS_REGION" | |
ecr_login: | |
needs: ECR_Region | |
uses: ./.github/workflows/ecr-login.yml | |
with: | |
region: ${{ needs.ECR_Region.outputs.aws_region }} | |
build_and_push_frontend: | |
runs-on: ubuntu-latest | |
needs: ecr_login | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
with: | |
install: true | |
# Caching builds | |
- name: Cache Docker layers | |
uses: actions/cache@v2 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ hashFiles('klipbored-frontend/Dockerfile', 'klipbored-frontend/**') }}-${{ github.run_id }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Check for changes in frontend | |
id: check_frontend_changes | |
run: | | |
if git diff --name-only HEAD^ HEAD | grep -q '^klipbored-frontend/'; then | |
echo "frontend_changed=true" >> $GITHUB_ENV | |
echo "::set-output name=frontend_changed::true" | |
else | |
echo "frontend_changed=false" >> $GITHUB_ENV | |
echo "::set-output name=frontend_changed::false" | |
fi | |
- name: Build and Push Frontend Docker Image | |
if: steps.check_frontend_changes.outputs.frontend_changed == 'true' | |
run: | | |
docker build -t ${{ secrets.FRONTEND_REPO }}:latest ./klipbored-frontend | |
docker push ${{ secrets.FRONTEND_REPO }}:latest | |
build_and_push_backend: | |
runs-on: ubuntu-latest | |
needs: ecr_login | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
with: | |
install: true | |
# Caching builds | |
- name: Cache Docker layers | |
uses: actions/cache@v2 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ hashFiles('klipbored-backend/Dockerfile', 'klipbored-backend/**') }}-${{ github.run_id }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Check for changes in backend | |
id: check_backend_changes | |
run: | | |
if git diff --name-only HEAD^ HEAD | grep -q '^klipbored-backend/'; then | |
echo "backend_changed=true" >> $GITHUB_ENV | |
echo "::set-output name=backend_changed::true" | |
else | |
echo "backend_changed=false" >> $GITHUB_ENV | |
echo "::set-output name=backend_changed::false" | |
fi | |
- name: Build and Push Backend Docker Image | |
if: steps.check_backend_changes.outputs.backend_changed == 'true' | |
run: | | |
docker build -t ${{ secrets.BACKEND_REPO }}:latest ./klipbored-backend | |
docker push ${{ secrets.BACKEND_REPO }}:latest | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [build_and_push_frontend, build_and_push_backend] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Update Kubeconfig | |
run: | | |
aws eks update-kubeconfig --name ${{ secrets.EKS_CLUSTER_NAME }} --region ${{ env.AWS_REGION }} | |
- name: Deploy Frontend to EKS | |
if: needs.build_and_push_frontend.outputs.frontend_changed == 'true' | |
run: | | |
kubectl apply -f ./k8s/frontend-deployment.yaml | |
- name: Deploy Backend to EKS | |
if: needs.build_and_push_backend.outputs.backend_changed == 'true' | |
run: | | |
kubectl apply -f ./k8s/backend-deployment.yaml |