Skip to content
Merged

Fix #21

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 45 additions & 17 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '22'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json

Expand Down Expand Up @@ -72,10 +72,10 @@ jobs:
path: backend/target/*.jar
retention-days: 1

# Docker Build and Push
dev-build-docker-image:
# Docker Build and Push - Frontend
dev-build-frontend-docker:
runs-on: ubuntu-latest
needs: [dev-frontend-build, dev-backend-build]
needs: [dev-frontend-build]
if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/fix'
permissions:
contents: read
Expand All @@ -90,6 +90,35 @@ jobs:
name: frontend-dist
path: frontend/dist/

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKER_SERVER }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Frontend Docker image
run: |
FRONTEND_IMAGE_TAG="${{ env.DOCKER_SERVER }}/${{ github.repository }}-frontend:${{ env.VERSION }}-${{ github.run_id }}"
docker build -t ${FRONTEND_IMAGE_TAG} ./frontend
docker push ${FRONTEND_IMAGE_TAG}
echo "Frontend image ${FRONTEND_IMAGE_TAG} pushed"

# Docker Build and Push - Backend
dev-build-backend-docker:
runs-on: ubuntu-latest
needs: [dev-backend-build]
if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/fix'
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download backend JAR
uses: actions/download-artifact@v4
with:
Expand All @@ -106,21 +135,17 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
env:
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
- name: Build and push Backend Docker image
run: |
IMAGE_TAG="${{ env.DOCKER_SERVER }}/${{ github.repository }}-dev:${{ env.VERSION }}-${{ github.run_id }}"
docker build -t ${IMAGE_TAG} .
docker push ${IMAGE_TAG}
echo "image ${IMAGE_TAG} pushed"
BACKEND_IMAGE_TAG="${{ env.DOCKER_SERVER }}/${{ github.repository }}-backend:${{ env.VERSION }}-${{ github.run_id }}"
docker build -t ${BACKEND_IMAGE_TAG} ./backend
docker push ${BACKEND_IMAGE_TAG}
echo "Backend image ${BACKEND_IMAGE_TAG} pushed"

# Kubernetes Deployment
dev-apply-deployment:
runs-on: ubuntu-latest
needs: dev-build-docker-image
needs: [dev-build-frontend-docker, dev-build-backend-docker]
if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/fix'
steps:
- name: Checkout code
Expand Down Expand Up @@ -170,9 +195,11 @@ jobs:
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
IMAGE_TAG="${{ env.DOCKER_SERVER }}/${{ github.repository }}-dev:${{ env.VERSION }}-${{ github.run_id }}"
FRONTEND_IMAGE_TAG="${{ env.DOCKER_SERVER }}/${{ github.repository }}-frontend:${{ env.VERSION }}-${{ github.run_id }}"
BACKEND_IMAGE_TAG="${{ env.DOCKER_SERVER }}/${{ github.repository }}-backend:${{ env.VERSION }}-${{ github.run_id }}"

export IMAGE="${IMAGE_TAG}"
export FRONTEND_IMAGE="${FRONTEND_IMAGE_TAG}"
export BACKEND_IMAGE="${BACKEND_IMAGE_TAG}"
export NAMESPACE="${{ env.NAMESPACE_DEV }}"

envsubst < kubernetes/deployment.yaml > kubernetes/deployment.generated.yaml
Expand All @@ -181,4 +208,5 @@ jobs:
cat kubernetes/deployment.generated.yaml

kubectl apply -f kubernetes/deployment.generated.yaml
echo "Application deployed with image: ${IMAGE_TAG}"
echo "Frontend deployed with image: ${FRONTEND_IMAGE_TAG}"
echo "Backend deployed with image: ${BACKEND_IMAGE_TAG}"
Loading