Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
letsgetrusty committed Jul 17, 2024
0 parents commit 1fe4784
Show file tree
Hide file tree
Showing 24 changed files with 3,368 additions and 0 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Build, Test and Deploy to Prod

# Trigger the workflow when changes are pushed to the main branch
on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
# Checkout code from the repository
- name: Checkout code
uses: actions/checkout@v2

# Cache dependencies to speed up build times
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
app-service/.cargo
app-service/target/
auth-service/.cargo
auth-service/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable

- name: Build and test app-service code
working-directory: ./app-service
run: |
cargo build --verbose
cargo test --verbose
- name: Build and test auth-service code
working-directory: ./auth-service
run: |
cargo build --verbose
cargo test --verbose
# Set up Docker Buildx for multi-platform builds
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker images
uses: docker/bake-action@v2.3.0
with:
push: true
files: |
compose.yml
compose.override.yml
set: |
*.cache-from=type=gha
*.cache-to=type=gha,mode=max
deploy:
needs: build
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Install sshpass
run: sudo apt-get install sshpass

- name: Copy compose.yml to droplet
run: sshpass -v -p ${{ secrets.DROPLET_PASSWORD }} scp -o StrictHostKeyChecking=no compose.yml root@${{ vars.DROPLET_IP }}:~

- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ vars.DROPLET_IP }}
username: root
password: ${{ secrets.DROPLET_PASSWORD }}
script: |
cd ~
export AUTH_SERVICE_IP=${{ vars.DROPLET_IP }}
docker compose down
docker compose pull
docker compose up -d
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Setup & Building
```bash
cargo install cargo-watch
cd app-service
cargo build
cd ..
cd auth-service
cargo build
cd ..
```

## Run servers locally (Manually)
#### App service
```bash
cd app-service
cargo watch -q -c -w src/ -w assets/ -w templates/ -x run
```

visit http://localhost:8000

#### Auth service
```bash
cd auth-service
cargo watch -q -c -w src/ -w assets/ -x run
```

visit http://localhost:3000

## Run servers locally (Docker)
```bash
docker compose build
docker compose up
```

visit http://localhost:8000 and http://localhost:3000
4 changes: 4 additions & 0 deletions app-service/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
target/
tests/
Dockerfile
1 change: 1 addition & 0 deletions app-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
Loading

0 comments on commit 1fe4784

Please sign in to comment.