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
16 changes: 16 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copy this file to .env and fill in your real credentials.
# Do NOT commit your .env file with real secrets!

# Docker Hub credentials
DOCKERHUB_USERNAME=your-dockerhub-username
DOCKERHUB_TOKEN=your-dockerhub-token

# SSH deploy settings
SERVER_HOST=your.vm.external.ip
SERVER_USER=your_vm_username

# SSH private key (for GitHub Actions only—do NOT use a raw key here)
# Instead, add the key as a secret in your GitHub repo
SERVER_SSH_KEY="-----BEGIN OPENSSH PRIVATE KEY-----
<PASTE YOUR PRIVATE KEY HERE>
-----END OPENSSH PRIVATE KEY-----"
73 changes: 40 additions & 33 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,67 @@
# .github/workflows/cd.yml
name: CD

on:
push:
branches: [ main ]
branches: [ test-2 ]
workflow_dispatch:

jobs:
build-and-push:
build-push-deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

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

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

- name: Build & push frontend image
uses: docker/build-push-action@v4
with:
context: ./frontend
push: true
tags: dastraus007/notes-app-frontend:latest

- name: Build & push backend image
uses: docker/build-push-action@v4
with:
context: ./backend
file: ./backend/Dockerfile
push: true
tags: dastraus007/notes-app-backend:latest

deploy-to-vm:
runs-on: ubuntu-latest
needs: build-and-push
steps:
- name: Copy docker‑compose.yml to server
uses: appleboy/scp-action@v0.1.8
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
source: docker-compose.yml
target: /home/${{ secrets.SERVER_USER }}/notes-app/

- name: SSH & deploy
uses: appleboy/ssh-action@v0.1.8
- name: Build & push frontend image
uses: docker/build-push-action@v4
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
cd notes-app
context: ./frontend
file: ./frontend/Dockerfile
push: true
tags: dastraus007/notes-app-frontend:latest

- name: Set up SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SERVER_SSH_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts

- name: Bootstrap VM
run: |
ssh -i ~/.ssh/id_ed25519 ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << 'EOF'
sudo apt update
sudo apt install -y docker.io docker-compose
sudo usermod -aG docker $USER
mkdir -p ~/notes-app
EOF

- name: Copy docker-compose.yml to server
run: |
scp -i ~/.ssh/id_ed25519 \
docker-compose.yml \
${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:~/notes-app/

- name: Deploy on server
run: |
ssh -i ~/.ssh/id_ed25519 ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << 'EOF'
cd ~/notes-app
docker-compose pull
docker-compose down
docker-compose up -d --remove-orphans
EOF
36 changes: 22 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
push:
branches: [ main ]
branches: [ test-2 ]
pull_request:

jobs:
Expand All @@ -13,19 +13,27 @@ jobs:
service: [frontend, backend]

steps:
- uses: actions/checkout@v3
# 1) Check out your code
- name: Checkout code
uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
# 2) Use Node.js
- name: Setup Node.js for ${{ matrix.service }}
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install & lint ${{ matrix.service }}
working-directory: ./${{ matrix.service }}
run: |
npm ci
npm run lint
# 3) Install dependencies
- name: Install dependencies
working-directory: ./${{ matrix.service }}
run: npm ci

- name: Test ${{ matrix.service }}
working-directory: ./${{ matrix.service }}
run: npm test
# 4) Lint if you defined a lint script
- name: Lint (optional)
working-directory: ./${{ matrix.service }}
run: npm run lint --if-present

# 5) Test if you defined a test script
- name: Test (optional)
working-directory: ./${{ matrix.service }}
run: npm run test --if-present
33 changes: 5 additions & 28 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
services:
version: "3.9"

services:
backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: notes-backend
image: dastraus007/notes-app-backend:latest
ports:
- "5000:5000"
environment:
- NODE_ENV=production
volumes:
- notes-data:/app
networks:
- notes-network
restart: unless-stopped

frontend:
build:
context: ./frontend
dockerfile: Dockerfile
container_name: notes-frontend
image: dastraus007/notes-app-frontend:latest
ports:
- "80:80"
depends_on:
- backend
networks:
- notes-network
restart: unless-stopped

networks:
notes-network:
driver: bridge

volumes:
notes-data: