From 83dd8faf45a6f196ccfdc5da46eee8d3c2493753 Mon Sep 17 00:00:00 2001 From: NikitaBuffy Date: Thu, 5 Dec 2024 14:55:57 +0300 Subject: [PATCH 01/16] #5 build(devops): add GitHub Actions pipeline for backend pull requests --- .github/workflows/backend.yml | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/backend.yml diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml new file mode 100644 index 0000000..c58c096 --- /dev/null +++ b/.github/workflows/backend.yml @@ -0,0 +1,43 @@ +name: Java CI + +on: + pull_request: + branches: + - backend + workflow_dispatch: + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Cache Maven dependencies + uses: actions/cache@v4 + with: + path: ~/.m2 + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Build project + run: | + cd backend + mvn clean verify + + - name: Analyze with SonarCloud + run: | + cd backend + mvn sonar:sonar \ + -Dsonar.projectKey=${{ secrets.SONAR_PROJECT_KEY }} \ + -Dsonar.organization=${{ secrets.SONAR_ORGANIZATION }} \ + -Dsonar.host.url=https://sonarcloud.io \ + -Dsonar.login=${{ secrets.SONAR_TOKEN }} \ No newline at end of file From cad046142a43a52f3154c621b7603fbd0c9bd379 Mon Sep 17 00:00:00 2001 From: NikitaBuffy Date: Thu, 5 Dec 2024 15:05:56 +0300 Subject: [PATCH 02/16] #5 fix(devops): fix java version in backend pipeline --- .github/workflows/backend.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index c58c096..9b38ff7 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -17,7 +17,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '21' distribution: 'temurin' - name: Cache Maven dependencies From f4c482addcb228a6c5f74b07020355b57729a21e Mon Sep 17 00:00:00 2001 From: NikitaBuffy Date: Thu, 5 Dec 2024 15:56:21 +0300 Subject: [PATCH 03/16] #5 fix(devops): delete sonar cloud check --- .github/workflows/backend.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 9b38ff7..5afb7e6 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -31,13 +31,4 @@ jobs: - name: Build project run: | cd backend - mvn clean verify - - - name: Analyze with SonarCloud - run: | - cd backend - mvn sonar:sonar \ - -Dsonar.projectKey=${{ secrets.SONAR_PROJECT_KEY }} \ - -Dsonar.organization=${{ secrets.SONAR_ORGANIZATION }} \ - -Dsonar.host.url=https://sonarcloud.io \ - -Dsonar.login=${{ secrets.SONAR_TOKEN }} \ No newline at end of file + mvn -B clean package \ No newline at end of file From 8480fa395445d76181e4d5329fda48d8d61760b1 Mon Sep 17 00:00:00 2001 From: NikitaBuffy Date: Fri, 6 Dec 2024 12:25:18 +0300 Subject: [PATCH 04/16] #5 build(devops): add SonarQube analyzation with pull request decoration --- .github/workflows/backend.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 5afb7e6..261dc19 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -31,4 +31,19 @@ jobs: - name: Build project run: | cd backend - mvn -B clean package \ No newline at end of file + mvn clean verify + + - name: Cache SonarQube packages + uses: actions/cache@v4 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + + - name: Analyze with SonarQube + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + run: | + cd backend + mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=NikitaBuffy_lenka-messenger_2c716e46-ed88-4385-b66c-97e4f1653f48 -Dsonar.projectName='lenka-messenger' -Dsonar.pullrequest.key=${{ github.event.number}} -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} -Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }} -Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} \ No newline at end of file From e03935c1b4ba7dae6567e63cf7ab4d5fe095b27a Mon Sep 17 00:00:00 2001 From: NikitaBuffy Date: Fri, 6 Dec 2024 13:06:02 +0300 Subject: [PATCH 05/16] #4 build(devops): add GitHub Actions pipeline for frontend pull requests --- .github/workflows/frontend.yml | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/frontend.yml diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml new file mode 100644 index 0000000..c854f08 --- /dev/null +++ b/.github/workflows/frontend.yml @@ -0,0 +1,49 @@ +name: Vue CI + +on: + pull_request: + branches: + - frontend + workflow_dispatch: + +jobs: + build-and-analyze: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Cache Node.js dependencies + uses: actions/cache@v4 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - name: Install dependencies + run: npm install + + - name: Build frontend + run: npm run build + + - name: Cache SonarQube packages + uses: actions/cache@v4 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + + - name: Analyze with SonarQube + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + run: | + cd frontend + npx sonar-scanner -Dsonar.projectKey=NikitaBuffy_lenka-messenger_2c716e46-ed88-4385-b66c-97e4f1653f48 -Dsonar.projectName='lenka-messenger' -Dsonar.sources=src -Dsonar.pullrequest.key=${{ github.event.number}} -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} -Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }} -Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} \ No newline at end of file From f210f89a8b6563490313444b08ebc214c57e0d41 Mon Sep 17 00:00:00 2001 From: NikitaBuffy Date: Fri, 6 Dec 2024 14:25:07 +0300 Subject: [PATCH 06/16] #4 build(devops): fix frontend pipeline --- .github/workflows/frontend.yml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index c854f08..1760c86 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -28,10 +28,20 @@ jobs: ${{ runner.os }}-node- - name: Install dependencies - run: npm install + run: | + cd frontend + npm install - name: Build frontend - run: npm run build + run: | + cd frontend + npm run build + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' - name: Cache SonarQube packages uses: actions/cache@v4 @@ -44,6 +54,7 @@ jobs: env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY }} run: | cd frontend - npx sonar-scanner -Dsonar.projectKey=NikitaBuffy_lenka-messenger_2c716e46-ed88-4385-b66c-97e4f1653f48 -Dsonar.projectName='lenka-messenger' -Dsonar.sources=src -Dsonar.pullrequest.key=${{ github.event.number}} -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} -Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }} -Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} \ No newline at end of file + npx sonar-scanner -Dsonar.projectKey=$SONAR_PROJECT_KEY -Dsonar.projectName='lenka-messenger' -Dsonar.sources=src -Dsonar.pullrequest.key=${{ github.event.number}} -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} -Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }} -Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} -Dsonar.host.url=$SONAR_HOST_URL \ No newline at end of file From c2a88e12d69cf14256d05a938c486b180aef76e9 Mon Sep 17 00:00:00 2001 From: NikitaBuffy Date: Fri, 6 Dec 2024 14:27:28 +0300 Subject: [PATCH 07/16] #4 refactor(devops): move sonar project key to github secret variable --- .github/workflows/backend.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 261dc19..dff69a1 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -44,6 +44,7 @@ jobs: env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY }} run: | cd backend - mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=NikitaBuffy_lenka-messenger_2c716e46-ed88-4385-b66c-97e4f1653f48 -Dsonar.projectName='lenka-messenger' -Dsonar.pullrequest.key=${{ github.event.number}} -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} -Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }} -Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} \ No newline at end of file + mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=$SONAR_PROJECT_KEY -Dsonar.projectName='lenka-messenger' -Dsonar.pullrequest.key=${{ github.event.number}} -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} -Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }} -Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} \ No newline at end of file From 51838e334e838e2cdb5a0974823fd10f0c63fddc Mon Sep 17 00:00:00 2001 From: NikitaBuffy Date: Fri, 6 Dec 2024 14:34:09 +0300 Subject: [PATCH 08/16] #4 build(devops): add restriction for creating pull request to main branch --- .github/workflows/main-restrict.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/main-restrict.yml diff --git a/.github/workflows/main-restrict.yml b/.github/workflows/main-restrict.yml new file mode 100644 index 0000000..0e5a9cd --- /dev/null +++ b/.github/workflows/main-restrict.yml @@ -0,0 +1,23 @@ +name: Restrict PR to Main + +on: + pull_request: + branches: + - main + +jobs: + restrict-branches: + runs-on: ubuntu-latest + steps: + - name: Check source branch + run: | + echo "Checking source branch..." + ALLOWED_BRANCHES=("backend" "frontend" "devops") + SOURCE_BRANCH=$(echo "${{ github.event.pull_request.head.ref }}") + + if [[ ! " ${ALLOWED_BRANCHES[@]} " =~ " ${SOURCE_BRANCH} " ]]; then + echo "Pull Request from branch '${SOURCE_BRANCH}' to 'main' is not allowed!" + exit 1 + else + echo "Pull Request from '${SOURCE_BRANCH}' is allowed." + fi \ No newline at end of file From 26a5c23e4209423074ea08e0126c4fd9dae7c4e9 Mon Sep 17 00:00:00 2001 From: NikitaBuffy Date: Sat, 7 Dec 2024 20:15:45 +0300 Subject: [PATCH 09/16] add github codeowners file --- .github/CODEOWNERS | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..d1810b3 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +# Repo owner +* @NikitaBuffy \ No newline at end of file From 9d2301d3f61d8df5a884cf1e174ae146e77b998b Mon Sep 17 00:00:00 2001 From: NikitaBuffy Date: Mon, 9 Dec 2024 10:53:13 +0300 Subject: [PATCH 10/16] #3 build(devops): add docker-compose, Dockerfiles --- .gitignore | 3 + backend/Dockerfile | 3 + backend/pom.xml | 26 ++++---- .../src/main/resources/application.properties | 11 ++++ docker-compose.yaml | 60 +++++++++++++++++++ frontend/Dockerfile | 4 ++ 6 files changed, 94 insertions(+), 13 deletions(-) create mode 100644 backend/Dockerfile create mode 100644 docker-compose.yaml create mode 100644 frontend/Dockerfile diff --git a/.gitignore b/.gitignore index 8627e50..7f75622 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ # Logs /logs/ + +# Environment +.env \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..f33ddb7 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,3 @@ +FROM amazoncorretto:21-alpine-jdk +COPY target/*.jar lm-backend.jar +ENTRYPOINT ["java", "-jar", "/lm-backend.jar"] \ No newline at end of file diff --git a/backend/pom.xml b/backend/pom.xml index 79ef988..3b7b262 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -25,14 +25,14 @@ org.springframework.boot spring-boot-starter-actuator - - - - - - - - + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-security + org.springframework.boot spring-boot-starter-web @@ -42,11 +42,11 @@ spring-boot-starter-websocket - - - - - + + org.postgresql + postgresql + runtime + org.projectlombok lombok diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 286afee..62c3ecf 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -1 +1,12 @@ +server.port=8080 spring.application.name=lenka-messenger + +spring.jpa.hibernate.ddl-auto=none +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +spring.jpa.properties.hibernate.format_sql=true +spring.sql.init.mode=always + +spring.datasource.driverClassName=org.postgresql.Driver +spring.datasource.url=${SPRING_DATASOURCE_URL} +spring.datasource.username=${POSTGRES_USER} +spring.datasource.password=${POSTGRES_PASSWORD} \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..a62dbfe --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,60 @@ +version: '3.9' + +services: + lm-backend: + build: + context: ./backend + container_name: lm-backend + image: lm-backend:latest + ports: + - "8080:8080" + depends_on: + - postgres + environment: + - SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/lenkamessenger + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + networks: + - app-network + restart: unless-stopped + + lm-frontend: + build: + context: ./frontend + container_name: lm-frontend + image: lm-frontend:latest + ports: + - "80:80" + networks: + - app-network + restart: unless-stopped + + postgres: + image: postgres:14-alpine + container_name: postgres + ports: + - "6551:5432" + volumes: + - /srv/postgresql-data:/var/lib/postgresql/data + environment: + - POSTGRES_DB=lenkamessenger + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - TZ=GMT + networks: + - app-network + + pgadmin: + image: dpage/pgadmin4 + container_name: pgadmin + environment: + PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL} + PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD} + ports: + - "5050:80" + networks: + - app-network + +networks: + app-network: + driver: bridge \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..24eb1c5 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,4 @@ +FROM nginx:1.25-alpine +COPY dist /usr/share/nginx/html +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file From 82a790acfbc81e72ef198c13bb922268a043fedc Mon Sep 17 00:00:00 2001 From: NikitaBuffy Date: Mon, 9 Dec 2024 14:56:12 +0300 Subject: [PATCH 11/16] #7 refactor(devops): change Dockerfile for frontend --- frontend/Dockerfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 24eb1c5..39ba972 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,4 +1,3 @@ -FROM nginx:1.25-alpine -COPY dist /usr/share/nginx/html -EXPOSE 80 -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file +FROM caddy:alpine +COPY ./dist /usr/share/caddy +EXPOSE 80 \ No newline at end of file From 98664c8c449d6aa8ed09f34b59eb28c6ed734ea7 Mon Sep 17 00:00:00 2001 From: NikitaBuffy Date: Mon, 9 Dec 2024 14:56:43 +0300 Subject: [PATCH 12/16] #7 build(devops): add CI/CD pipeline for main branch --- .github/workflows/main.yml | 47 +++++++++++++++ docker-compose.dev.yaml | 58 +++++++++++++++++++ ...r-compose.yaml => docker-compose.prod.yaml | 10 +--- 3 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 docker-compose.dev.yaml rename docker-compose.yaml => docker-compose.prod.yaml (88%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..a99152d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,47 @@ +name: Main CI/CD + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + build-image-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - 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 Frontend Image + run: | + cd frontend + docker build -t nickpominov/lm-frontend:latest . + docker push nickpominov/lm-frontend:latest + + - name: Build and Push Backend Image + run: | + cd backend + docker build -t nickpominov/lm-backend:latest . + docker push nickpominov/lm-backend:latest + + - name: Deploy to remote server + uses: appleboy/ssh-action@v0.1.7 + with: + host: ${{ secrets.SERVER_IP }} + username: ${{ secrets.SSH_USERNAME }} + password: ${{ secrets.SSH_PASSWORD }} + port: 22 + script: | + cd /srv/lenka-messenger + docker-compose -f docker-compose.prod.yaml up -d --no-deps lm-backend lm-frontend \ No newline at end of file diff --git a/docker-compose.dev.yaml b/docker-compose.dev.yaml new file mode 100644 index 0000000..8264936 --- /dev/null +++ b/docker-compose.dev.yaml @@ -0,0 +1,58 @@ +version: '3.9' + +services: + lm-backend: + build: + context: ./backend + container_name: lm-backend + ports: + - "8080:8080" + depends_on: + - postgres + environment: + - SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/lenkamessenger + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + networks: + - app-network + restart: unless-stopped + + lm-frontend: + build: + context: ./frontend + container_name: lm-frontend + ports: + - "3000:80" + networks: + - app-network + restart: unless-stopped + + postgres: + image: postgres:14-alpine + container_name: postgres + ports: + - "6551:5432" + volumes: + - /var/lib/postgresql/data + environment: + - POSTGRES_DB=lenkamessenger + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - TZ=GMT + networks: + - app-network + + pgadmin: + image: dpage/pgadmin4 + container_name: pgadmin + environment: + PGADMIN_DEFAULT_EMAIL: admin@admin.ru + PGADMIN_DEFAULT_PASSWORD: admin + ports: + - "5050:80" + networks: + - app-network + +networks: + app-network: + driver: bridge \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.prod.yaml similarity index 88% rename from docker-compose.yaml rename to docker-compose.prod.yaml index a62dbfe..198fdd3 100644 --- a/docker-compose.yaml +++ b/docker-compose.prod.yaml @@ -2,10 +2,8 @@ version: '3.9' services: lm-backend: - build: - context: ./backend + image: nickpominov/lm-backend:latest container_name: lm-backend - image: lm-backend:latest ports: - "8080:8080" depends_on: @@ -19,12 +17,10 @@ services: restart: unless-stopped lm-frontend: - build: - context: ./frontend + image: nickpominov/lm-frontend:latest container_name: lm-frontend - image: lm-frontend:latest ports: - - "80:80" + - "3000:80" networks: - app-network restart: unless-stopped From 17fbbd9f18a77339aa092d2a0ad158829020d7a7 Mon Sep 17 00:00:00 2001 From: NikitaBuffy Date: Mon, 9 Dec 2024 15:36:21 +0300 Subject: [PATCH 13/16] #7 build(devops): save build artifacts from CI pipelines --- .github/workflows/backend.yml | 6 ++++++ .github/workflows/frontend.yml | 6 ++++++ .github/workflows/main.yml | 12 ++++++++++++ 3 files changed, 24 insertions(+) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index dff69a1..422dc40 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -33,6 +33,12 @@ jobs: cd backend mvn clean verify + - name: Upload backend build artifact + uses: actions/upload-artifact@v4 + with: + name: backend-jar + path: /backend/target/*.jar + - name: Cache SonarQube packages uses: actions/cache@v4 with: diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 1760c86..42f301b 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -37,6 +37,12 @@ jobs: cd frontend npm run build + - name: Upload frontend build artifact + uses: actions/upload-artifact@v4 + with: + name: frontend-dist + path: frontend/dist/ + - name: Set up JDK 17 uses: actions/setup-java@v4 with: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a99152d..22fb7ad 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,6 +23,18 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} + - name: Download backend artifact + uses: actions/download-artifact@v4 + with: + name: backend-jar + path: backend/target/ + + - name: Download frontend artifact + uses: actions/download-artifact@v4 + with: + name: frontend-dist + path: frontend/dist/ + - name: Build and Push Frontend Image run: | cd frontend From 822b8dd2867c7c3601cf8b2d24035e34d3cd7df8 Mon Sep 17 00:00:00 2001 From: NikitaBuffy Date: Mon, 9 Dec 2024 16:15:49 +0300 Subject: [PATCH 14/16] #7 refactor(devops): refactor main.yml for main CD pipeline --- .github/workflows/main.yml | 58 ++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 22fb7ad..72a48de 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,13 +1,13 @@ -name: Main CI/CD +name: Main CD on: - push: - branches: - - main + pull_request: + types: [closed] workflow_dispatch: jobs: - build-image-and-push: + cd-backend: + if: github.event.pull_request.merged == true && github.event.pull_request.head.ref == 'backend' runs-on: ubuntu-latest steps: @@ -23,13 +23,47 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - name: Download backend artifact + - name: Download Backend Artifact uses: actions/download-artifact@v4 with: name: backend-jar path: backend/target/ - - name: Download frontend artifact + - name: Build and Push Backend Image + run: | + cd backend + docker build -t nickpominov/lm-backend:latest . + docker push nickpominov/lm-backend:latest + + - name: Deploy Backend to Remote Server + uses: appleboy/ssh-action@v0.1.7 + with: + host: ${{ secrets.SERVER_IP }} + username: ${{ secrets.SSH_USERNAME }} + password: ${{ secrets.SSH_PASSWORD }} + port: 22 + script: | + cd /srv/lenka-messenger + docker-compose -f docker-compose.prod.yaml up -d --no-deps lm-backend + + cd-frontend: + if: github.event.pull_request.merged == true && github.event.pull_request.head.ref == 'frontend' + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - 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: Download Frontend Artifact uses: actions/download-artifact@v4 with: name: frontend-dist @@ -41,13 +75,7 @@ jobs: docker build -t nickpominov/lm-frontend:latest . docker push nickpominov/lm-frontend:latest - - name: Build and Push Backend Image - run: | - cd backend - docker build -t nickpominov/lm-backend:latest . - docker push nickpominov/lm-backend:latest - - - name: Deploy to remote server + - name: Deploy Frontend to Remote Server uses: appleboy/ssh-action@v0.1.7 with: host: ${{ secrets.SERVER_IP }} @@ -56,4 +84,4 @@ jobs: port: 22 script: | cd /srv/lenka-messenger - docker-compose -f docker-compose.prod.yaml up -d --no-deps lm-backend lm-frontend \ No newline at end of file + docker-compose -f docker-compose.prod.yaml up -d --no-deps lm-frontend \ No newline at end of file From 6328fa948c7b8d6c6017f4c876762db282ae4fc4 Mon Sep 17 00:00:00 2001 From: NikitaBuffy Date: Tue, 10 Dec 2024 09:26:28 +0300 Subject: [PATCH 15/16] #7 fix(devops): adjust Main CD pipeline only for main branch --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 72a48de..32e367a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,6 +3,8 @@ name: Main CD on: pull_request: types: [closed] + branches: + - main workflow_dispatch: jobs: From 8829d35a3d773ccb6aba3802fc0c360c4bd455e6 Mon Sep 17 00:00:00 2001 From: NikitaBuffy Date: Tue, 10 Dec 2024 10:39:52 +0300 Subject: [PATCH 16/16] #34 test(frontend): changes for testing CI/CD pipeline --- frontend/src/App.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 8f3e196..2427ae6 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -1,6 +1,6 @@