diff --git a/.github/workflows/backend-build-push.yml b/.github/workflows/backend-build-push.yml deleted file mode 100644 index cbbc796..0000000 --- a/.github/workflows/backend-build-push.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Build and Push Backend Image - -on: - push: - branches: [ main ] - paths: - - 'backend/**' - workflow_dispatch: - -env: - REGISTRY: docker.io - IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/notes-app-backend - -jobs: - build-and-push-backend: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Log in to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Extract metadata for backend - id: meta-backend - uses: docker/metadata-action@v5 - with: - images: ${{ env.IMAGE_NAME }} - tags: | - type=ref,event=branch - type=ref,event=pr - type=sha,prefix={{branch}}- - type=raw,value=latest,enable={{is_default_branch}} - - - name: Build and push backend image - uses: docker/build-push-action@v5 - with: - context: ./backend - file: ./backend/Dockerfile - push: true - tags: ${{ steps.meta-backend.outputs.tags }} - labels: ${{ steps.meta-backend.outputs.labels }} \ No newline at end of file diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..9433f91 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,60 @@ +name: CD + +on: + push: + branches: [ main ] + workflow_dispatch: + +jobs: + build-and-push: + 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 + 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 + 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 + 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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4b5321f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,31 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + +jobs: + build-and-test: + runs-on: ubuntu-latest + strategy: + matrix: + service: [frontend, backend] + + steps: + - uses: actions/checkout@v3 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + + - name: Install & lint ${{ matrix.service }} + working-directory: ./${{ matrix.service }} + run: | + npm ci + npm run lint + + - name: Test ${{ matrix.service }} + working-directory: ./${{ matrix.service }} + run: npm test diff --git a/.github/workflows/frontend-build-push.yml b/.github/workflows/frontend-build-push.yml deleted file mode 100644 index ae0f90a..0000000 --- a/.github/workflows/frontend-build-push.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Build and Push Frontend Image - -on: - push: - branches: [ main ] - paths: - - 'frontend/**' - workflow_dispatch: - -env: - REGISTRY: docker.io - IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/notes-app-frontend - -jobs: - build-and-push-frontend: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Log in to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Extract metadata for frontend - id: meta-frontend - uses: docker/metadata-action@v5 - with: - images: ${{ env.IMAGE_NAME }} - tags: | - type=ref,event=branch - type=ref,event=pr - type=sha,prefix={{branch}}- - type=raw,value=latest,enable={{is_default_branch}} - - - name: Build and push frontend image - uses: docker/build-push-action@v5 - with: - context: ./frontend - file: ./frontend/Dockerfile - push: true - tags: ${{ steps.meta-frontend.outputs.tags }} - labels: ${{ steps.meta-frontend.outputs.labels }} \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 8ff035a..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Rider ignored files -/projectSettingsUpdater.xml -/.idea.DevOpsCourse.iml -/modules.xml -/contentModel.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml deleted file mode 100644 index e82600c..0000000 --- a/.idea/AndroidProjectSystem.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index df87cf9..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/indexLayout.xml b/.idea/indexLayout.xml deleted file mode 100644 index 7b08163..0000000 --- a/.idea/indexLayout.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..44b1b5b --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# Notes‑App CI/CD + +## What’s here + +- **CI** (`ci.yml`): on push/PR builds, lints & tests both services. +- **CD** (`cd.yml`): on merge to `main`, builds Docker images, pushes to Docker Hub, then SSHs into your VM and does a rolling `docker-compose up`. + +## Prerequisites + +1. **VM** must have Docker & Docker Compose installed. +2. SSH key (with passphrase‑less access) in `~/.ssh/authorized_keys`. +3. GitHub Secrets configured: + - `DOCKERHUB_USERNAME`, `DOCKERHUB_TOKEN` + - `SERVER_HOST`, `SERVER_USER`, `SERVER_SSH_KEY` + +## Usage + +- Push or PR → ✅ CI runs. +- Merge into `main` → ✅ CD runs automatically. +- You can also manually trigger CD in the Actions tab (workflow_dispatch). + diff --git a/Screenshot 2025-07-12 221204.png b/Screenshot 2025-07-12 221204.png new file mode 100644 index 0000000..20ec9fd Binary files /dev/null and b/Screenshot 2025-07-12 221204.png differ diff --git a/photo_2025-07-12_22-10-59.jpg b/photo_2025-07-12_22-10-59.jpg new file mode 100644 index 0000000..b9bc4a0 Binary files /dev/null and b/photo_2025-07-12_22-10-59.jpg differ diff --git a/photo_2025-07-12_22-11-06.jpg b/photo_2025-07-12_22-11-06.jpg new file mode 100644 index 0000000..43b0513 Binary files /dev/null and b/photo_2025-07-12_22-11-06.jpg differ