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
63 changes: 63 additions & 0 deletions .github/workflows/staging-build-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Build and Deploy to Staging Server

on:
workflow_dispatch:

jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment: staging

steps:
- name: Checkout repository
uses: actions/checkout@v4

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

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build all modules
run: |
./gradlew clean build -p aics-admin -x test
./gradlew clean build -p aics-api -x test
./gradlew clean build -p aics-auth -x test

- name: Build Docker images
run: |
docker build -t aics-admin:${GITHUB_SHA} -f aics-admin/Dockerfile aics-admin
docker build -t aics-api:${GITHUB_SHA} -f aics-api/Dockerfile aics-api
docker build -t aics-auth:${GITHUB_SHA} -f aics-auth/Dockerfile aics-auth

- name: Save Docker images as tar
run: |
mkdir -p deploy
docker save aics-admin:${GITHUB_SHA} -o deploy/aics-admin.tar
docker save aics-api:${GITHUB_SHA} -o deploy/aics-api.tar
docker save aics-auth:${GITHUB_SHA} -o deploy/aics-auth.tar

- name: Upload Docker images to server
uses: appleboy/scp-action@v1.0.0
with:
host: ${{ secrets.STAGING_SERVER_HOST }}
username: ${{ secrets.STAGING_SERVER_USERNAME }}
password: ${{ secrets.STAGING_SERVER_PASSWORD }}
port: ${{ secrets.STAGING_SERVER_PORT }}
source: "deploy/*"
target: ${{ secrets.STAGING_DEPLOY_PATH }}

- name: Deploy on server
uses: appleboy/ssh-action@v1.1.0
with:
host: ${{ secrets.STAGING_SERVER_HOST }}
username: ${{ secrets.STAGING_SERVER_USERNAME }}
password: ${{ secrets.STAGING_SERVER_PASSWORD }}
port: ${{ secrets.STAGING_SERVER_PORT }}
script: |
cd ${{ secrets.STAGING_DEPLOY_PATH }}
chmod +x backend/deploy.sh
./backend/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/abouts")
@RequestMapping("/api/v1/admin/abouts")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public class AboutAdminControllerImpl implements AboutAdminController {
private final AboutAdminFacade aboutAdminFacade;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/carousels")
@RequestMapping("/api/v1/admin/carousels")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public class CarouselAdminControllerImpl implements CarouselAdminController {
private final CarouselAdminFacade carouselAdminFacade;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/clubs")
@RequestMapping("/api/v1/admin/clubs")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public class ClubAdminControllerImpl implements ClubAdminController {
private final ClubAdminFacade clubAdminFacade;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/comments")
@RequestMapping("/api/v1/admin/comments")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public class CommentAdminControllerImpl implements CommentAdminController {
private final CommentAdminFacade commentAdminFacade;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/files")
@RequestMapping("/api/v1/admin/files")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public class FileAdminControllerImpl implements FileAdminController {
private final FileAdminFacade fileAdminFacade;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/labs")
@RequestMapping("/api/v1/admin/labs")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public class LabAdminControllerImpl implements LabAdminController{
private final LabAdminFacade labAdminFacade;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/posts")
@RequestMapping("/api/v1/admin/posts")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public class PostAdminControllerImpl implements PostAdminController {
private final PostAdminFacade postAdminFacade;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/professors")
@RequestMapping("/api/v1/admin/professors")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public class ProfessorAdminControllerImpl implements ProfessorAdminController {
private final ProfessorAdminFacade professorAdminFacade;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/users")
@RequestMapping("/api/v1/admin/users")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public class UserAdminControllerImpl implements UserAdminController {
private final UserAdminFacade userAdminFacade;
Expand Down
8 changes: 7 additions & 1 deletion aics-admin/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ spring:
redis:
host: ${REDIS_HOST:redis}
port: ${REDIS_PORT:6379}
password: ${REDIS_PASSWORD}
password: ${REDIS_PASSWORD}

springdoc:
swagger-ui:
enabled: false
api-docs:
enabled: false
8 changes: 7 additions & 1 deletion aics-api/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ spring:
redis:
host: ${REDIS_HOST:redis}
port: ${REDIS_PORT:6379}
password: ${REDIS_PASSWORD}
password: ${REDIS_PASSWORD}

springdoc:
swagger-ui:
enabled: false
api-docs:
enabled: false
8 changes: 7 additions & 1 deletion aics-auth/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ spring:
redis:
host: ${REDIS_HOST:redis}
port: ${REDIS_PORT:6379}
password: ${REDIS_PASSWORD}
password: ${REDIS_PASSWORD}

springdoc:
swagger-ui:
enabled: false
api-docs:
enabled: false
20 changes: 20 additions & 0 deletions deploy/staging/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -e

APP_HOME=$(pwd)/backend

echo "===== Loading Docker images ====="
sudo docker load -i $APP_HOME/tar/aics-api.tar
sudo docker tag aics-admin:${GITHUB_SHA} aics-admin:latest
sudo docker load -i $APP_HOME/tar/aics-admin.tar
sudo docker tag aics-auth:${GITHUB_SHA} aics-auth:latest
sudo docker load -i $APP_HOME/tar/aics-auth.tar
sudo docker tag aics-api:${GITHUB_SHA} aics-api:latest

echo "===== Stopping existing containers ====="
sudo docker compose -f $APP_HOME/docker-compose.yml down || true

echo "===== Starting containers ====="
sudo docker compose -f $APP_HOME/docker-compose.yml --env-file $APP_HOME/.env up -d

echo "===== Deployment finished ====="
4 changes: 4 additions & 0 deletions docker/staging/docker-compose-db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include:
- networks.yml
- service-postgres.yml
- service-redis.yml
4 changes: 4 additions & 0 deletions docker/staging/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include:
- networks.yml
- service-application.yml
- service-nginx.yml
3 changes: 3 additions & 0 deletions docker/staging/networks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
networks:
aics-network:
driver: bridge
60 changes: 60 additions & 0 deletions docker/staging/service/service-application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
services:
aics-api:
image: aics-api:latest
container_name: aics-api
env_file:
- .env
environment:
SPRING_PROFILES_ACTIVE: prod
DB_HOST: postgres
DB_PORT: 5432
DB_NAME: ${POSTGRES_DB}
DB_USERNAME: ${POSTGRES_USER}
DB_PASSWORD: ${POSTGRES_PASSWORD}
JWT_ISSUER: kgudevelopers@gmail.com
JWT_SECRET_KEY: ${JWT_SECRET_KEY}
REDIS_HOST: redis
REDIS_PASSWORD: ${REDIS_PASSWORD}
FILE_SECRET_KEY: ${FILE_SECRET_KEY}
networks:
- aics-network

aics-admin:
image: aics-admin:latest
container_name: aics-admin
env_file:
- .env
environment:
SPRING_PROFILES_ACTIVE: prod
DB_HOST: postgres
DB_PORT: 5432
DB_NAME: ${POSTGRES_DB}
DB_USERNAME: ${POSTGRES_USER}
DB_PASSWORD: ${POSTGRES_PASSWORD}
JWT_ISSUER: kgudevelopers@gmail.com
JWT_SECRET_KEY: ${JWT_SECRET_KEY}
REDIS_HOST: redis
REDIS_PASSWORD: ${REDIS_PASSWORD}
FILE_SECRET_KEY: ${FILE_SECRET_KEY}
networks:
- aics-network

aics-auth:
image: aics-auth:latest
container_name: aics-auth
env_file:
- .env
environment:
SPRING_PROFILES_ACTIVE: prod
DB_HOST: postgres
DB_PORT: 5432
DB_NAME: ${POSTGRES_DB}
DB_USERNAME: ${POSTGRES_USER}
DB_PASSWORD: ${POSTGRES_PASSWORD}
JWT_ISSUER: kgudevelopers@gmail.com
JWT_SECRET_KEY: ${JWT_SECRET_KEY}
REDIS_HOST: redis
REDIS_PASSWORD: ${REDIS_PASSWORD}
FILE_SECRET_KEY: ${FILE_SECRET_KEY}
networks:
- aics-network
9 changes: 9 additions & 0 deletions docker/staging/service/service-nginx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
nginx:
image: nginx:latest
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "80:80"
networks:
- aics-network
20 changes: 20 additions & 0 deletions docker/staging/service/service-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
services:
postgres:
image: postgres:15
container_name: postgres
restart: always
env_file:
- .env
ports:
- "5432:5432"
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- postgres-data:/var/lib/postgresql/data
networks:
- aics-network

volumes:
postgres-data:
12 changes: 12 additions & 0 deletions docker/staging/service/service-redis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
redis:
image: redis:latest
container_name: redis
restart: always
command: ["redis-server", "--requirepass", "${REDIS_PASSWORD}"]
env_file:
- .env
environment:
REDIS_PASSWORD: ${REDIS_PASSWORD}
networks:
- aics-network
33 changes: 33 additions & 0 deletions nginx/staging/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
server {
listen 80;

location ^~ /api/v1/auth/ {
proxy_pass http://aics-auth:8082/api/v1/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Origin $http_origin;
}

location ^~ /api/v1/admin/ {
proxy_pass http://aics-admin:8081/api/v1/admin/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Origin $http_origin;
}

location ^~ /api/v1/ {
proxy_pass http://aics-api:8080/api/v1/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Origin $http_origin;
}

location / {
proxy_pass http://aics-app:3000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}