Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Strawbang committed Dec 2, 2024
1 parent f27db29 commit b4089d1
Show file tree
Hide file tree
Showing 27 changed files with 2,581 additions and 435 deletions.
25 changes: 25 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Database Configuration
MYSQL_ROOT_PASSWORD=change_this_root_password
MYSQL_DATABASE=consultant_tracking
MYSQL_USER=change_this_user
MYSQL_PASSWORD=change_this_password

# Spring Configuration
SPRING_DATASOURCE_URL=jdbc:mariadb://mariadb:3306/consultant_tracking
SPRING_DATASOURCE_USERNAME=${MYSQL_USER}
SPRING_DATASOURCE_PASSWORD=${MYSQL_PASSWORD}
SPRING_JPA_HIBERNATE_DDL_AUTO=validate
SPRING_JPA_SHOW_SQL=true
SPRING_JPA_FORMAT_SQL=true

# Liquibase Configuration
LIQUIBASE_COMMAND_USERNAME=${MYSQL_USER}
LIQUIBASE_COMMAND_PASSWORD=${MYSQL_PASSWORD}
LIQUIBASE_COMMAND_URL=${SPRING_DATASOURCE_URL}
LIQUIBASE_SEARCH_PATH=/liquibase/changelog
LIQUIBASE_COMMAND_CHANGELOG_FILE=./db.changelog.xml

# Domains Configuration
DOMAIN_FRONTEND=app.localhost
DOMAIN_BACKEND=api.localhost
DOMAIN_ADMINER=adminer.localhost
120 changes: 120 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: CI/CD Pipeline

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
REGISTRY: ghcr.io
BACKEND_IMAGE_NAME: ${{ github.repository }}/backend
FRONTEND_IMAGE_NAME: ${{ github.repository }}/frontend
MYSQL_DATABASE: consultant_tracking
DOMAIN_FRONTEND: app.example.com
DOMAIN_BACKEND: api.example.com
DOMAIN_ADMINER: adminer.example.com

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

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

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create .env file
run: |
cat << EOF > .env
MYSQL_ROOT_PASSWORD=${{ secrets.MYSQL_ROOT_PASSWORD }}
MYSQL_DATABASE=${{ env.MYSQL_DATABASE }}
MYSQL_USER=${{ secrets.MYSQL_USER }}
MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }}
SPRING_DATASOURCE_URL=jdbc:mariadb://mariadb:3306/${{ env.MYSQL_DATABASE }}
SPRING_DATASOURCE_USERNAME=${{ secrets.MYSQL_USER }}
SPRING_DATASOURCE_PASSWORD=${{ secrets.MYSQL_PASSWORD }}
SPRING_JPA_HIBERNATE_DDL_AUTO=validate
SPRING_JPA_SHOW_SQL=false
SPRING_JPA_FORMAT_SQL=false
DOMAIN_FRONTEND=${{ env.DOMAIN_FRONTEND }}
DOMAIN_BACKEND=${{ env.DOMAIN_BACKEND }}
DOMAIN_ADMINER=${{ env.DOMAIN_ADMINER }}
EOF
- name: Build and push Backend Docker image
uses: docker/build-push-action@v4
with:
context: ./backend
push: true
tags: ${{ env.REGISTRY }}/${{ env.BACKEND_IMAGE_NAME }}:latest
build-args: |
SPRING_DATASOURCE_URL=jdbc:mariadb://mariadb:3306/${{ env.MYSQL_DATABASE }}
SPRING_DATASOURCE_USERNAME=${{ secrets.MYSQL_USER }}
SPRING_DATASOURCE_PASSWORD=${{ secrets.MYSQL_PASSWORD }}
- name: Build and push Frontend Docker image
uses: docker/build-push-action@v4
with:
context: ./frontend
push: true
tags: ${{ env.REGISTRY }}/${{ env.FRONTEND_IMAGE_NAME }}:latest
build-args: |
API_URL=https://${{ env.DOMAIN_BACKEND }}
deploy:
needs: build-and-push
runs-on: ubuntu-latest

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

- name: Create .env file on server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
cat << EOF > ~/consultant-tracking/.env
MYSQL_ROOT_PASSWORD=${{ secrets.MYSQL_ROOT_PASSWORD }}
MYSQL_DATABASE=${{ env.MYSQL_DATABASE }}
MYSQL_USER=${{ secrets.MYSQL_USER }}
MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }}
SPRING_DATASOURCE_URL=jdbc:mariadb://mariadb:3306/${{ env.MYSQL_DATABASE }}
SPRING_DATASOURCE_USERNAME=${{ secrets.MYSQL_USER }}
SPRING_DATASOURCE_PASSWORD=${{ secrets.MYSQL_PASSWORD }}
SPRING_JPA_HIBERNATE_DDL_AUTO=validate
SPRING_JPA_SHOW_SQL=false
SPRING_JPA_FORMAT_SQL=false
DOMAIN_FRONTEND=${{ env.DOMAIN_FRONTEND }}
DOMAIN_BACKEND=${{ env.DOMAIN_BACKEND }}
DOMAIN_ADMINER=${{ env.DOMAIN_ADMINER }}
EOF
- name: Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
cd ~/consultant-tracking
docker pull ${{ env.REGISTRY }}/${{ env.BACKEND_IMAGE_NAME }}:latest
docker pull ${{ env.REGISTRY }}/${{ env.FRONTEND_IMAGE_NAME }}:latest
docker-compose down
docker-compose up -d
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Environment variables
.env
.env.*
!.env.example

# IDE files
.idea/
.vscode/
*.iml

# Dependencies
node_modules/
/dist/
/target/

# Logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# System Files
.DS_Store
Thumbs.db
Loading

0 comments on commit b4089d1

Please sign in to comment.