From 3184aa3882fdeebcb4a82325d02946e73884be35 Mon Sep 17 00:00:00 2001 From: dastraus007 Date: Tue, 5 Aug 2025 21:56:21 +0300 Subject: [PATCH 01/12] add Secrets --- .env.example | 16 ++++++++++ .github/workflows/cd.yml | 67 +++++++++++++--------------------------- .github/workflows/ci.yml | 61 ++++++++++++++++++++++++------------ 3 files changed, 79 insertions(+), 65 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..760982a --- /dev/null +++ b/.env.example @@ -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----- + +-----END OPENSSH PRIVATE KEY-----" diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 9433f91..451f449 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,60 +1,35 @@ -name: CD +name: CI on: push: branches: [ main ] - workflow_dispatch: + pull_request: jobs: - build-and-push: + build-and-test: runs-on: ubuntu-latest + strategy: + matrix: + service: [frontend, backend] + steps: - uses: actions/checkout@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Log in to Docker Hub - uses: docker/login-action@v2 + - name: Use Node.js ${{ matrix.service }} + uses: actions/setup-node@v3 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + node-version: '18' - - name: Build & push frontend image - uses: docker/build-push-action@v4 - with: - context: ./frontend - push: true - tags: dastraus007/notes-app-frontend:latest + - name: Install dependencies for ${{ matrix.service }} + working-directory: ./${{ matrix.service }} + run: npm ci - - name: Build & push backend image - uses: docker/build-push-action@v4 - with: - context: ./backend - push: true - tags: dastraus007/notes-app-backend:latest + # Only run lint if you’ve added it to package.json: + - name: Lint ${{ matrix.service }} + if: ${{ hashFiles(format('{0}/package.json', matrix.service)) != '' && contains(fromJson(runner.os), 'Linux') }} # simple guard + working-directory: ./${{ matrix.service }} + run: npm run lint || echo "no lint script, skipping" - 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 - with: - host: ${{ secrets.SERVER_HOST }} - username: ${{ secrets.SERVER_USER }} - key: ${{ secrets.SERVER_SSH_KEY }} - script: | - cd notes-app - docker-compose pull - docker-compose down - docker-compose up -d --remove-orphans + - name: Test ${{ matrix.service }} + working-directory: ./${{ matrix.service }} + run: npm test diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b5321f..25f9cda 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,31 +1,54 @@ -name: CI +name: CD on: push: branches: [ main ] - pull_request: + workflow_dispatch: jobs: - build-and-test: + build-push-deploy: runs-on: ubuntu-latest - strategy: - matrix: - service: [frontend, backend] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v3 - - name: Use Node.js - uses: actions/setup-node@v3 - with: - node-version: '18' + # 1) log in to Docker Hub + - name: Docker Hub login + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Install & lint ${{ matrix.service }} - working-directory: ./${{ matrix.service }} - run: | - npm ci - npm run lint + # 2) build & push both images + - name: Build & push images + uses: docker/build-push-action@v4 + with: + context: . + push: true + # adjust your tags as needed: + tags: | + dastraus007/notes-app-frontend:latest + dastraus007/notes-app-backend:latest - - name: Test ${{ matrix.service }} - working-directory: ./${{ matrix.service }} - run: npm test + # 3) copy only your compose file up to the VM + - name: Copy docker-compose.yml to server + uses: appleboy/scp-action@v0.1.1 + 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/ + + # 4) SSH in, pull new images & restart + - name: SSH & deploy + uses: appleboy/ssh-action@v0.1.8 + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USER }} + key: ${{ secrets.SERVER_SSH_KEY }} + script: | + cd notes-app + docker-compose pull + docker-compose down + docker-compose up -d --remove-orphans From 70ee2c8d830c7791a4f248d30232e609a8edf949 Mon Sep 17 00:00:00 2001 From: dastraus007 Date: Tue, 5 Aug 2025 22:00:26 +0300 Subject: [PATCH 02/12] fix ci --- .github/workflows/ci.yml | 66 ++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25f9cda..8eb78e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,54 +1,40 @@ -name: CD +name: CI on: push: branches: [ main ] - workflow_dispatch: + pull_request: jobs: - build-push-deploy: + build-and-test: runs-on: ubuntu-latest + strategy: + matrix: + service: [frontend, backend] steps: - - uses: actions/checkout@v3 + # 1) Check out the code + - name: Checkout repository + uses: actions/checkout@v3 - # 1) log in to Docker Hub - - name: Docker Hub login - uses: docker/login-action@v2 + # 2) Set up Node.js + - name: Use Node.js ${{ matrix.service }} + uses: actions/setup-node@v3 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + node-version: '18' - # 2) build & push both images - - name: Build & push images - uses: docker/build-push-action@v4 - with: - context: . - push: true - # adjust your tags as needed: - tags: | - dastraus007/notes-app-frontend:latest - dastraus007/notes-app-backend:latest + # 3) Install dependencies + - name: Install dependencies for ${{ matrix.service }} + working-directory: ./${{ matrix.service }} + run: npm ci - # 3) copy only your compose file up to the VM - - name: Copy docker-compose.yml to server - uses: appleboy/scp-action@v0.1.1 - 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/ + # 4) (Optional) Lint, if you have a lint script and are on Linux + - name: Lint ${{ matrix.service }} + if: ${{ hashFiles(format('{0}/package.json', matrix.service)) != '' && contains(runner.os, 'Linux') }} + working-directory: ./${{ matrix.service }} + run: npm run lint || echo "no lint script, skipping" - # 4) SSH in, pull new images & restart - - name: SSH & deploy - uses: appleboy/ssh-action@v0.1.8 - with: - host: ${{ secrets.SERVER_HOST }} - username: ${{ secrets.SERVER_USER }} - key: ${{ secrets.SERVER_SSH_KEY }} - script: | - cd notes-app - docker-compose pull - docker-compose down - docker-compose up -d --remove-orphans + # 5) Run tests + - name: Test ${{ matrix.service }} + working-directory: ./${{ matrix.service }} + run: npm test From 9cba1c2412093c054cfb5fe1815efdab2df0b689 Mon Sep 17 00:00:00 2001 From: dastraus007 Date: Tue, 5 Aug 2025 22:02:16 +0300 Subject: [PATCH 03/12] fix run: npm run test --if-present --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8eb78e8..54b28e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: working-directory: ./${{ matrix.service }} run: npm run lint || echo "no lint script, skipping" - # 5) Run tests + # 5) Run tests only if a "test" script is defined - name: Test ${{ matrix.service }} working-directory: ./${{ matrix.service }} - run: npm test + run: npm run test --if-present From 391a2ce14e7303dc6108d0fc58ceb51208560a49 Mon Sep 17 00:00:00 2001 From: dastraus007 Date: Tue, 5 Aug 2025 22:04:26 +0300 Subject: [PATCH 04/12] fix ci --- .github/workflows/ci.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 54b28e2..eef2b08 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: service: [frontend, backend] steps: - # 1) Check out the code + # 1) Checkout the code - name: Checkout repository uses: actions/checkout@v3 @@ -21,20 +21,19 @@ jobs: - name: Use Node.js ${{ matrix.service }} uses: actions/setup-node@v3 with: - node-version: '18' + node-version: '18' # Match your project's Node version # 3) Install dependencies - name: Install dependencies for ${{ matrix.service }} working-directory: ./${{ matrix.service }} run: npm ci - # 4) (Optional) Lint, if you have a lint script and are on Linux + # 4) (Optional) Lint if defined - name: Lint ${{ matrix.service }} - if: ${{ hashFiles(format('{0}/package.json', matrix.service)) != '' && contains(runner.os, 'Linux') }} working-directory: ./${{ matrix.service }} - run: npm run lint || echo "no lint script, skipping" + run: npm run lint --if-present - # 5) Run tests only if a "test" script is defined + # 5) Run tests if defined - name: Test ${{ matrix.service }} working-directory: ./${{ matrix.service }} run: npm run test --if-present From 069c9d81dc8a11ea64c479c00490247d3f7c4deb Mon Sep 17 00:00:00 2001 From: dastraus007 Date: Tue, 5 Aug 2025 22:06:28 +0300 Subject: [PATCH 05/12] fix --- .github/workflows/ci.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eef2b08..b64e341 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,27 +13,27 @@ jobs: service: [frontend, backend] steps: - # 1) Checkout the code - - name: Checkout repository + # 1) Check out your code + - name: Checkout code uses: actions/checkout@v3 - # 2) Set up Node.js - - name: Use Node.js ${{ matrix.service }} + # 2) Use Node.js + - name: Setup Node.js ${{ matrix.service }} uses: actions/setup-node@v3 with: - node-version: '18' # Match your project's Node version + node-version: '18' # 3) Install dependencies - name: Install dependencies for ${{ matrix.service }} working-directory: ./${{ matrix.service }} run: npm ci - # 4) (Optional) Lint if defined + # 4) (Optional) Lint if you defined it - name: Lint ${{ matrix.service }} working-directory: ./${{ matrix.service }} run: npm run lint --if-present - # 5) Run tests if defined + # 5) (Optional) Test if you defined it - name: Test ${{ matrix.service }} working-directory: ./${{ matrix.service }} run: npm run test --if-present From 207526da534faf1abcbf59668e3c3579f5ea24a0 Mon Sep 17 00:00:00 2001 From: dastraus007 Date: Tue, 5 Aug 2025 22:08:31 +0300 Subject: [PATCH 06/12] fix --- .github/workflows/ci.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b64e341..f50a2ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,27 +13,22 @@ jobs: service: [frontend, backend] steps: - # 1) Check out your code - name: Checkout code uses: actions/checkout@v3 - # 2) Use Node.js - name: Setup Node.js ${{ matrix.service }} uses: actions/setup-node@v3 with: node-version: '18' - # 3) Install dependencies - name: Install dependencies for ${{ matrix.service }} working-directory: ./${{ matrix.service }} run: npm ci - # 4) (Optional) Lint if you defined it - - name: Lint ${{ matrix.service }} + - name: Lint ${{ matrix.service }} (optional) working-directory: ./${{ matrix.service }} run: npm run lint --if-present - # 5) (Optional) Test if you defined it - - name: Test ${{ matrix.service }} + - name: Test ${{ matrix.service }} (optional) working-directory: ./${{ matrix.service }} run: npm run test --if-present From a956ec6756ab33c03c2cc38f7b4a5243f815ae00 Mon Sep 17 00:00:00 2001 From: dastraus007 Date: Tue, 5 Aug 2025 22:18:17 +0300 Subject: [PATCH 07/12] fix ci cd --- .github/workflows/cd.yml | 64 +++++++++++++++++++++++++++------------- .github/workflows/ci.yml | 13 +++++--- 2 files changed, 52 insertions(+), 25 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 451f449..773e2ac 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,35 +1,57 @@ -name: CI +name: CD on: push: branches: [ main ] - pull_request: + workflow_dispatch: jobs: - build-and-test: + build-push-deploy: runs-on: ubuntu-latest - strategy: - matrix: - service: [frontend, backend] steps: - - uses: actions/checkout@v3 + # 1) Checkout the repo + - name: Checkout code + uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.service }} - uses: actions/setup-node@v3 + # 2) Log in to Docker Hub + - name: Docker Hub login + uses: docker/login-action@v2 with: - node-version: '18' + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Install dependencies for ${{ matrix.service }} - working-directory: ./${{ matrix.service }} - run: npm ci + # 3) Build & push your images + - name: Build & push images + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: | + dastraus007/notes-app-frontend:latest + dastraus007/notes-app-backend:latest + + # 4) Prepare SSH (write key & known_hosts) + - name: Set up SSH for deploy + 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 - # Only run lint if you’ve added it to package.json: - - name: Lint ${{ matrix.service }} - if: ${{ hashFiles(format('{0}/package.json', matrix.service)) != '' && contains(fromJson(runner.os), 'Linux') }} # simple guard - working-directory: ./${{ matrix.service }} - run: npm run lint || echo "no lint script, skipping" + # 5) Copy docker-compose.yml to the server + - name: Copy compose file + run: | + scp -i ~/.ssh/id_ed25519 \ + docker-compose.yml \ + ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:~/notes-app/ - - name: Test ${{ matrix.service }} - working-directory: ./${{ matrix.service }} - run: npm test + # 6) SSH in and deploy + - 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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f50a2ef..deb8f96 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,22 +13,27 @@ jobs: service: [frontend, backend] steps: + # 1) Check out your code - name: Checkout code uses: actions/checkout@v3 - - name: Setup Node.js ${{ matrix.service }} + # 2) Use Node.js + - name: Setup Node.js for ${{ matrix.service }} uses: actions/setup-node@v3 with: node-version: '18' - - name: Install dependencies for ${{ matrix.service }} + # 3) Install dependencies + - name: Install dependencies working-directory: ./${{ matrix.service }} run: npm ci - - name: Lint ${{ matrix.service }} (optional) + # 4) Lint if you defined a lint script + - name: Lint (optional) working-directory: ./${{ matrix.service }} run: npm run lint --if-present - - name: Test ${{ matrix.service }} (optional) + # 5) Test if you defined a test script + - name: Test (optional) working-directory: ./${{ matrix.service }} run: npm run test --if-present From 15e11e1e014925e357a35856d0222c7af988225e Mon Sep 17 00:00:00 2001 From: dastraus007 Date: Tue, 5 Aug 2025 23:56:49 +0300 Subject: [PATCH 08/12] fix --- .github/workflows/cd.yml | 19 +++++++++++-------- .github/workflows/ci.yml | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 773e2ac..65023bb 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,8 +1,9 @@ +# .github/workflows/cd.yml name: CD on: push: - branches: [ main ] + branches: [ test-1 ] workflow_dispatch: jobs: @@ -10,18 +11,15 @@ jobs: runs-on: ubuntu-latest steps: - # 1) Checkout the repo - name: Checkout code uses: actions/checkout@v3 - # 2) Log in to Docker Hub - name: Docker Hub login uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - # 3) Build & push your images - name: Build & push images uses: docker/build-push-action@v4 with: @@ -31,7 +29,6 @@ jobs: dastraus007/notes-app-frontend:latest dastraus007/notes-app-backend:latest - # 4) Prepare SSH (write key & known_hosts) - name: Set up SSH for deploy run: | mkdir -p ~/.ssh @@ -39,14 +36,20 @@ jobs: chmod 600 ~/.ssh/id_ed25519 ssh-keyscan -H ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts - # 5) Copy docker-compose.yml to the server - - name: Copy compose file + - name: Bootstrap VM (install Docker & Compose) + 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 + 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/ - # 6) SSH in and deploy - name: Deploy on server run: | ssh -i ~/.ssh/id_ed25519 ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << 'EOF' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index deb8f96..0ea2fdf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: CI on: push: - branches: [ main ] + branches: [ test-1 ] pull_request: jobs: From 412c0c5004dbdcf5fb8fa3e3b7747ca73d73e2d3 Mon Sep 17 00:00:00 2001 From: dastraus007 Date: Wed, 6 Aug 2025 00:13:09 +0300 Subject: [PATCH 09/12] fix --- .github/workflows/cd.yml | 2 +- .github/workflows/ci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 65023bb..7c3f5f5 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -3,7 +3,7 @@ name: CD on: push: - branches: [ test-1 ] + branches: [ test-2 ] workflow_dispatch: jobs: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ea2fdf..fd8e03f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: CI on: push: - branches: [ test-1 ] + branches: [ test-2 ] pull_request: jobs: From 3cddec960c393aa1f6d790fd6350bb0ea65cc1e7 Mon Sep 17 00:00:00 2001 From: dastraus007 Date: Wed, 6 Aug 2025 00:21:39 +0300 Subject: [PATCH 10/12] fix --- .github/workflows/cd.yml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 7c3f5f5..ac99977 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -11,24 +11,38 @@ jobs: runs-on: ubuntu-latest steps: + # 1) Checkout the repo - name: Checkout code uses: actions/checkout@v3 + # 2) 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 images + # 3) Build & push the backend image + - name: Build & push backend image uses: docker/build-push-action@v4 with: - context: . + context: ./backend + file: ./backend/Dockerfile push: true tags: | - dastraus007/notes-app-frontend:latest dastraus007/notes-app-backend:latest + # 4) Build & push the frontend image + - name: Build & push frontend image + uses: docker/build-push-action@v4 + with: + context: ./frontend + file: ./frontend/Dockerfile + push: true + tags: | + dastraus007/notes-app-frontend:latest + + # 5) Prepare SSH for deploy - name: Set up SSH for deploy run: | mkdir -p ~/.ssh @@ -36,6 +50,7 @@ jobs: chmod 600 ~/.ssh/id_ed25519 ssh-keyscan -H ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts + # 6) Bootstrap VM (install Docker & Compose) - name: Bootstrap VM (install Docker & Compose) run: | ssh -i ~/.ssh/id_ed25519 ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << 'EOF' @@ -44,12 +59,14 @@ jobs: sudo usermod -aG docker $USER EOF + # 7) Copy docker-compose.yml to the server - name: Copy docker-compose.yml to server run: | scp -i ~/.ssh/id_ed25519 \ docker-compose.yml \ ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:~/notes-app/ + # 8) SSH in and deploy updated containers - name: Deploy on server run: | ssh -i ~/.ssh/id_ed25519 ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << 'EOF' From 04555f133303a9df28341f5f61ea3f3b47ed16c9 Mon Sep 17 00:00:00 2001 From: dastraus007 Date: Wed, 6 Aug 2025 00:53:09 +0300 Subject: [PATCH 11/12] fix --- .github/workflows/cd.yml | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index ac99977..3f7cba9 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -11,38 +11,31 @@ jobs: runs-on: ubuntu-latest steps: - # 1) Checkout the repo - name: Checkout code uses: actions/checkout@v3 - # 2) Log in to Docker Hub - name: Docker Hub login uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - # 3) Build & push the backend image - 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 + tags: dastraus007/notes-app-backend:latest - # 4) Build & push the frontend image - name: Build & push frontend image uses: docker/build-push-action@v4 with: context: ./frontend file: ./frontend/Dockerfile push: true - tags: | - dastraus007/notes-app-frontend:latest + tags: dastraus007/notes-app-frontend:latest - # 5) Prepare SSH for deploy - name: Set up SSH for deploy run: | mkdir -p ~/.ssh @@ -50,7 +43,6 @@ jobs: chmod 600 ~/.ssh/id_ed25519 ssh-keyscan -H ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts - # 6) Bootstrap VM (install Docker & Compose) - name: Bootstrap VM (install Docker & Compose) run: | ssh -i ~/.ssh/id_ed25519 ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << 'EOF' @@ -59,14 +51,17 @@ jobs: sudo usermod -aG docker $USER EOF - # 7) Copy docker-compose.yml to the server + - name: Ensure remote deploy directory exists + run: | + ssh -i ~/.ssh/id_ed25519 ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} \ + "mkdir -p ~/notes-app" + - name: Copy docker-compose.yml to server run: | scp -i ~/.ssh/id_ed25519 \ docker-compose.yml \ ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:~/notes-app/ - # 8) SSH in and deploy updated containers - name: Deploy on server run: | ssh -i ~/.ssh/id_ed25519 ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << 'EOF' From 87f55b8870adb24a72e447639be093be4b9087e6 Mon Sep 17 00:00:00 2001 From: dastraus007 Date: Wed, 6 Aug 2025 00:57:45 +0300 Subject: [PATCH 12/12] fix --- .github/workflows/cd.yml | 13 ++++--------- docker-compose.yml | 33 +++++---------------------------- 2 files changed, 9 insertions(+), 37 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 3f7cba9..09e4876 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -11,8 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v3 + - uses: actions/checkout@v3 - name: Docker Hub login uses: docker/login-action@v2 @@ -36,26 +35,22 @@ jobs: push: true tags: dastraus007/notes-app-frontend:latest - - name: Set up SSH for deploy + - 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 (install Docker & Compose) + - 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: Ensure remote deploy directory exists - run: | - ssh -i ~/.ssh/id_ed25519 ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} \ - "mkdir -p ~/notes-app" - - name: Copy docker-compose.yml to server run: | scp -i ~/.ssh/id_ed25519 \ diff --git a/docker-compose.yml b/docker-compose.yml index 0769224..9cd4c37 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: \ No newline at end of file