Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit

Permalink
test: remove rds
Browse files Browse the repository at this point in the history
  • Loading branch information
amber committed Sep 29, 2024
1 parent 5b45405 commit e5db73e
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 37 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/build-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ jobs:
id: read_info
run: |
PUBLIC_IP=$(cat terraform/terraform-outputs/ec2_public_ip.txt)
RDS_ENDPOINT=$(cat terraform/terraform-outputs/rds_endpoint.txt)
RDS_PASSWORD=$(cat terraform/terraform-outputs/rds_password.txt)
echo "::set-output name=ec2_public_ip::$PUBLIC_IP"
echo "::set-output name=rds_endpoint::$RDS_ENDPOINT"
- name: SSH into EC2 and deploy
uses: appleboy/scp-action@v0.1.7
Expand All @@ -91,7 +88,8 @@ jobs:
echo "${{ secrets.EC2_SSH_KEY }}" > private_key && chmod 600 private_key
ssh -i private_key -o StrictHostKeyChecking=no ${{ secrets.EC2_USER }}@${{ steps.read_ip.outputs.ec2_public_ip }} << 'EOF'
echo "POSTGRES_USERNAME=${{ secrets.POSTGRES_USERNAME }}" >> .env
echo "POSTGRES_PASSWORD=${{ steps.read_info.outputs.rds_password }}" >> .env
echo "POSTGRES_URL=${{ steps.read_info.outputs.rds_endpoint }}" >> .env
echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD}" >> .env
echo "POSTGRES_URL=${{ secrets.POSTGRES_URL }}" >> .env
echo "POSTGRES_DB=${{ secrets.POSTGRES_DB }}" >> .env
docker compose up -d
EOF
2 changes: 1 addition & 1 deletion backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ spring:

datasource:
driverClassName: org.postgresql.Driver
url: jdbc:postgresql://${POSTGRES_URL}/nshm
url: ${POSTGRES_URL}
username: ${POSTGRES_USERNAME}
password: ${POSTGRES_PASSWORD}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,25 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Build Docker images
run: |
docker build -t z1yoon/nus-secondhand-market-frontend:latest -f frontend/Dockerfile .
docker build -t z1yoon/nus-secondhand-market-backend:latest ./backend

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Push Docker images
run: |
docker push z1yoon/nus-secondhand-market-frontend:latest
docker push z1yoon/nus-secondhand-market-backend:latest
- name: Build and push frontend
uses: docker/build-push-action@v6
with:
context: ./frontend
push: true
tags: z1yoon/nus-secondhand-market-frontend:latest

- name: Build and push backend
uses: docker/build-push-action@v6
with:
context: ./backend
push: true
tags: z1yoon/nus-secondhand-market-backend:latest

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
Expand Down Expand Up @@ -89,8 +90,8 @@ jobs:
run: |
echo "${{ secrets.EC2_SSH_KEY }}" > private_key && chmod 600 private_key
ssh -i private_key -o StrictHostKeyChecking=no ${{ secrets.EC2_USER }}@${{ steps.read_ip.outputs.ec2_public_ip }} << 'EOF'
echo "postgres_username=${{ secrets.POSTGRES_USERNAME }}" >> .env
echo "postgres_password=${{ steps.read_info.outputs.rds_password }}" >> .env
echo "rds_endpoint=${{ steps.read_info.outputs.rds_endpoint }}" >> .env
echo "POSTGRES_USERNAME=${{ secrets.POSTGRES_USERNAME }}" >> .env
echo "POSTGRES_PASSWORD=${{ steps.read_info.outputs.rds_password }}" >> .env
echo "POSTGRES_URL=${{ steps.read_info.outputs.rds_endpoint }}" >> .env
docker compose up -d
EOF
37 changes: 37 additions & 0 deletions terraform/backup/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
provider "aws" {
region = "ap-southeast-1"
}

module "vpc" {
source = "./modules/vpc"
}

module "ec2" {
source = "./modules/ec2"
subnet_id = module.vpc.subnet_ids[0]
vpc_security_group_id = module.vpc.security_group_id
}

module "rds" {
source = "./modules/rds"
vpc_security_group_id = module.vpc.security_group_id
subnet_ids = module.vpc.subnet_ids[1]

}

module "s3" {
source = "./modules/s3"
}

output "public_ip" {
value = module.ec2.public_ip
}

output "db_instance_endpoint" {
value = module.rds.db_instance_endpoint
}

output "db_instance_password" {
value = module.rds.db_instance_password
sensitive = true
}
16 changes: 0 additions & 16 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,10 @@ module "ec2" {
vpc_security_group_id = module.vpc.security_group_id
}

module "rds" {
source = "./modules/rds"
vpc_security_group_id = module.vpc.security_group_id
subnet_ids = module.vpc.subnet_ids[1]

}

module "s3" {
source = "./modules/s3"
}

output "public_ip" {
value = module.ec2.public_ip
}

output "db_instance_endpoint" {
value = module.rds.db_instance_endpoint
}

output "db_instance_password" {
value = module.rds.db_instance_password
sensitive = true
}

0 comments on commit e5db73e

Please sign in to comment.