Skip to content

Commit

Permalink
Merge pull request #48 from hngprojects/main
Browse files Browse the repository at this point in the history
Update dev with changes from main
  • Loading branch information
vicradon authored Jul 20, 2024
2 parents 2323197 + db339a6 commit ec84712
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 45 deletions.
28 changes: 13 additions & 15 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,27 @@ jobs:
runs-on: ubuntu-latest
needs: build
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: db_name
TEST_USERNAME: postgres
TEST_PASSWORD: password
TEST_DB_NAME: db_name
TEST_DB_HOST: localhost
TEST_DB_PORT: 5432
TEST_DB_CONNECTION: pgsql
TEST_TIMEZONE: Africa/Lagos
TEST_SSLMODE: disable
TEST_MIGRATE: true
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: ${{ env.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ env.POSTGRES_DB }}
POSTGRES_USER: ${{ env.TEST_USERNAME }}
POSTGRES_PASSWORD: ${{ env.TEST_PASSWORD }}
POSTGRES_DB: ${{ env.TEST_DB_NAME }}
ports:
- 5432:5432
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Create the app config file
run: cp app-sample.env app.env
- name: Run The Project
run: nohup go run main.go > /dev/null 2>&1 &
- name: Wait for application to start
run: sleep 30s
- name: Test for reachability
run: curl http://localhost:8019
- name: Run All Tests
run: go test ./... -timeout 99999s

Expand Down Expand Up @@ -78,7 +76,7 @@ jobs:
# Navigate to the repository directory and pull changes
cd $APPROOT || { echo "Failed to navigate to web root directory"; exit 1; }
git reset --hard HEAD || { echo "Failed to reset local changes"; exit 1; }
git pull origin main || { echo "Failed to pull latest changes"; exit 1; }
git pull origin dev || { echo "Failed to pull latest changes"; exit 1; }
else
git clone -b dev http://github.com/${{ github.repository }} . || { echo "Failed to clone repository"; exit 1; }
fi
Expand Down
26 changes: 12 additions & 14 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,27 @@ jobs:
runs-on: ubuntu-latest
needs: build
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: db_name
TEST_USERNAME: postgres
TEST_PASSWORD: password
TEST_DB_NAME: db_name
TEST_DB_HOST: localhost
TEST_DB_PORT: 5432
TEST_DB_CONNECTION: pgsql
TEST_TIMEZONE: Africa/Lagos
TEST_SSLMODE: disable
TEST_MIGRATE: true
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: ${{ env.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ env.POSTGRES_DB }}
POSTGRES_USER: ${{ env.TEST_USERNAME }}
POSTGRES_PASSWORD: ${{ env.TEST_PASSWORD }}
POSTGRES_DB: ${{ env.TEST_DB_NAME }}
ports:
- 5432:5432
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Create the app config file
run: cp app-sample.env app.env
- name: Run The Project
run: nohup go run main.go > /dev/null 2>&1 &
- name: Wait for application to start
run: sleep 30s
- name: Test for reachability
run: curl http://localhost:8019
- name: Run All Tests
run: go test ./... -timeout 99999s

Expand Down
28 changes: 13 additions & 15 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,27 @@ jobs:
runs-on: ubuntu-latest
needs: build
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: db_name
TEST_USERNAME: postgres
TEST_PASSWORD: password
TEST_DB_NAME: db_name
TEST_DB_HOST: localhost
TEST_DB_PORT: 5432
TEST_DB_CONNECTION: pgsql
TEST_TIMEZONE: Africa/Lagos
TEST_SSLMODE: disable
TEST_MIGRATE: true
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: ${{ env.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ env.POSTGRES_DB }}
POSTGRES_USER: ${{ env.TEST_USERNAME }}
POSTGRES_PASSWORD: ${{ env.TEST_PASSWORD }}
POSTGRES_DB: ${{ env.TEST_DB_NAME }}
ports:
- 5432:5432
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Create the app config file
run: cp app-sample.env app.env
- name: Run The Project
run: nohup go run main.go > /dev/null 2>&1 &
- name: Wait for application to start
run: sleep 30s
- name: Test for reachability
run: curl http://localhost:8019
- name: Run All Tests
run: go test ./... -timeout 99999s

Expand Down Expand Up @@ -78,7 +76,7 @@ jobs:
# Navigate to the repository directory and pull changes
cd $APPROOT || { echo "Failed to navigate to web root directory"; exit 1; }
git reset --hard HEAD || { echo "Failed to reset local changes"; exit 1; }
git pull origin main || { echo "Failed to pull latest changes"; exit 1; }
git pull origin staging || { echo "Failed to pull latest changes"; exit 1; }
else
git clone -b staging http://github.com/${{ github.repository }} . || { echo "Failed to clone repository"; exit 1; }
fi
Expand Down
42 changes: 42 additions & 0 deletions scripts/certbot_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# Variables
DOMAINS=(
"api-golang.boilerplate.hng.tech" # prod
"deployment.api-golang.boilerplate.hng.tech" # dev
"staging.api-golang.boilerplate.hng.tech" # staging
)
EMAIL="[email protected]" # Used for certbot notifications and recovery

# Update package lists
sudo apt update

# Install Snapd if not already installed
sudo apt install -y snapd

# Install the core snap & Ensure Snapd is up to date
sudo snap install core
sudo snap refresh core

# Remove any existing Certbot installations
sudo apt-get remove certbot

# Install Certbot using Snap
sudo snap install --classic certbot

# Create a symbolic link to make Certbot command globally available
sudo ln -s /snap/bin/certbot /usr/bin/certbot

# Obtain SSL certificates for each domain
for DOMAIN in "${DOMAINS[@]}"; do
echo "Configuring SSL for domain: $DOMAIN"
sudo certbot --nginx -d "$DOMAIN" --non-interactive --agree-tos --email "$EMAIL"
done

# Set up automatic renewal of the certificates
sudo crontab -l | { cat; echo "0 0,12 * * * root certbot renew --quiet"; } | sudo crontab -

# Display the configured domains
for DOMAIN in "${DOMAINS[@]}"; do
echo "SSL certificate configured for: https://$DOMAIN"
done
2 changes: 1 addition & 1 deletion scripts/setup_postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
DB_PASSWORD="password"

# Define the databases and users
DATABASES=("development" "staging" "production")
DATABASES=("development_db" "staging_db" "production_db")
USERS=("development_user" "staging_user" "production_user")

# Check if the script is running as root (necessary for changing PostgreSQL settings)
Expand Down

0 comments on commit ec84712

Please sign in to comment.