Skip to content
Merged
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
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI

on:
pull_request:
branches: [main]

jobs:
backend-test:
name: Backend — build & test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Java 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: temurin
cache: maven

- name: Run tests
working-directory: backend
run: mvn test

frontend-build:
name: Frontend — build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Node 20
uses: actions/setup-node@v4
with:
node-version: '20'
cache: npm
cache-dependency-path: frontend/package-lock.json

- name: Install dependencies
working-directory: frontend
run: npm ci

- name: Build
working-directory: frontend
run: npm run build
env:
VITE_API_BASE_URL: https://placeholder-for-ci-build-check
69 changes: 69 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Deploy

on:
push:
branches: [main]

env:
BACKEND_IMAGE: projectpulse-backend
FRONTEND_IMAGE: projectpulse-frontend

jobs:
deploy-backend:
name: Backend — build, push & deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Log in to Azure Container Registry
uses: azure/docker-login@v2
with:
login-server: ${{ secrets.ACR_LOGIN_SERVER }}
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}

- name: Build and push backend image
working-directory: backend
run: |
IMAGE=${{ secrets.ACR_LOGIN_SERVER }}/${{ env.BACKEND_IMAGE }}
docker build -t $IMAGE:${{ github.sha }} -t $IMAGE:latest .
docker push $IMAGE:${{ github.sha }}
docker push $IMAGE:latest

- name: Deploy to Azure App Service
uses: azure/webapps-deploy@v3
with:
app-name: ${{ secrets.BACKEND_APP_NAME }}
publish-profile: ${{ secrets.BACKEND_PUBLISH_PROFILE }}
images: ${{ secrets.ACR_LOGIN_SERVER }}/${{ env.BACKEND_IMAGE }}:${{ github.sha }}

deploy-frontend:
name: Frontend — build, push & deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Log in to Azure Container Registry
uses: azure/docker-login@v2
with:
login-server: ${{ secrets.ACR_LOGIN_SERVER }}
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}

- name: Build and push frontend image
working-directory: frontend
run: |
IMAGE=${{ secrets.ACR_LOGIN_SERVER }}/${{ env.FRONTEND_IMAGE }}
docker build \
--build-arg VITE_API_BASE_URL=${{ secrets.BACKEND_URL }} \
-t $IMAGE:${{ github.sha }} \
-t $IMAGE:latest .
docker push $IMAGE:${{ github.sha }}
docker push $IMAGE:latest

- name: Deploy to Azure App Service
uses: azure/webapps-deploy@v3
with:
app-name: ${{ secrets.FRONTEND_APP_NAME }}
publish-profile: ${{ secrets.FRONTEND_PUBLISH_PROFILE }}
images: ${{ secrets.ACR_LOGIN_SERVER }}/${{ env.FRONTEND_IMAGE }}:${{ github.sha }}
12 changes: 12 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM maven:3.9-eclipse-temurin-17 AS builder
WORKDIR /app
COPY pom.xml .
RUN mvn dependency:go-offline -q
COPY src ./src
RUN mvn package -DskipTests -q

FROM eclipse-temurin:17-jre-alpine
WORKDIR /app
COPY --from=builder /app/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-jar", "app.jar"]
5 changes: 5 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.tcu.projectpulse.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {

@Value("${app.cors-allowed-origin:http://localhost:5173}")
private String allowedOrigin;

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/**")
.allowedOrigins("http://localhost:5173")
.allowedOrigins(allowedOrigin)
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.allowCredentials(true);
Expand Down
21 changes: 21 additions & 0 deletions backend/src/main/resources/application-prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
spring:
datasource:
url: ${SPRING_DATASOURCE_URL}
username: ${SPRING_DATASOURCE_USERNAME}
password: ${SPRING_DATASOURCE_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: update
database-platform: org.hibernate.dialect.MySQLDialect
show-sql: false
h2:
console:
enabled: false

server:
port: 8080

app:
frontend-base-url: ${APP_FRONTEND_BASE_URL}
cors-allowed-origin: ${APP_CORS_ALLOWED_ORIGIN}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ class InstructorServiceTest {
private Student student;

// Shared date constants — "02-12-2024" is the week_start used across WAR tests
private static final LocalDate WEEK_START = LocalDate.of(2024, 2, 12);
private static final LocalDate WEEK_END = LocalDate.of(2024, 2, 18);
private static final LocalDate WEEK_START = LocalDate.of(2024, 2, 12);
private static final LocalDate WEEK_END = LocalDate.of(2024, 2, 18);
private static final LocalDate RANGE_END = LocalDate.of(2024, 4, 28);
private static final String WEEK_START_STR = "02-12-2024";
private static final String WEEK_END_STR = "04-28-2024";

Expand Down Expand Up @@ -364,7 +365,7 @@ void generateStudentPeerEvalReport_hasData_returnsRowsGroupedByWeek() {
pe.setEngagementInMeetings(9);
pe.setPublicComments("Excellent!");

given(peerEvaluationRepository.findByStudentIdAndWeekRange(1L, WEEK_START_STR, WEEK_END_STR))
given(peerEvaluationRepository.findByStudentIdAndWeekRange(1L, WEEK_START, RANGE_END))
.willReturn(List.of(pe));

List<PeerEvalReportRow> rows = instructorService
Expand All @@ -377,7 +378,7 @@ void generateStudentPeerEvalReport_hasData_returnsRowsGroupedByWeek() {

@Test
void generateStudentPeerEvalReport_noData_returnsEmptyList() {
given(peerEvaluationRepository.findByStudentIdAndWeekRange(1L, WEEK_START_STR, WEEK_END_STR))
given(peerEvaluationRepository.findByStudentIdAndWeekRange(1L, WEEK_START, RANGE_END))
.willReturn(List.of());

List<PeerEvalReportRow> rows = instructorService
Expand Down
Loading
Loading