Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#34 Изменен заголовок h1 для тестов CI/CD #35

Merged
merged 25 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0d120c3
Merge branch 'frontend' into 'main'
NikitaBuffy Dec 5, 2024
83dd8fa
#5 build(devops): add GitHub Actions pipeline for backend pull requests
NikitaBuffy Dec 5, 2024
cad0461
#5 fix(devops): fix java version in backend pipeline
NikitaBuffy Dec 5, 2024
f4c482a
#5 fix(devops): delete sonar cloud check
NikitaBuffy Dec 5, 2024
8480fa3
#5 build(devops): add SonarQube analyzation with pull request decoration
NikitaBuffy Dec 6, 2024
6d00e16
Merge branch 'devops_5' into 'devops'
NikitaBuffy Dec 6, 2024
e03935c
#4 build(devops): add GitHub Actions pipeline for frontend pull requests
NikitaBuffy Dec 6, 2024
f210f89
#4 build(devops): fix frontend pipeline
NikitaBuffy Dec 6, 2024
c2a88e1
#4 refactor(devops): move sonar project key to github secret variable
NikitaBuffy Dec 6, 2024
51838e3
#4 build(devops): add restriction for creating pull request to main b…
NikitaBuffy Dec 6, 2024
866bb7f
Merge branch 'devops_4' into 'devops'
NikitaBuffy Dec 6, 2024
80cfd4e
Merge branch 'devops' into 'main' from pull-request #19
NikitaBuffy Dec 6, 2024
26a5c23
add github codeowners file
NikitaBuffy Dec 7, 2024
c4c2b75
Merge branch 'devops' into 'main' from pull request #20
NikitaBuffy Dec 7, 2024
9d2301d
#3 build(devops): add docker-compose, Dockerfiles
NikitaBuffy Dec 9, 2024
12058c7
Merge branch 'devops_3' into 'devops' from pull request #28
NikitaBuffy Dec 9, 2024
82a790a
#7 refactor(devops): change Dockerfile for frontend
NikitaBuffy Dec 9, 2024
98664c8
#7 build(devops): add CI/CD pipeline for main branch
NikitaBuffy Dec 9, 2024
17fbbd9
#7 build(devops): save build artifacts from CI pipelines
NikitaBuffy Dec 9, 2024
822b8dd
#7 refactor(devops): refactor main.yml for main CD pipeline
NikitaBuffy Dec 9, 2024
5a5a18d
Merge branch 'devops_7' into 'devops' from pull request #31
NikitaBuffy Dec 10, 2024
d9390fa
Merge branch 'devops' into 'main' from pull request #32
NikitaBuffy Dec 10, 2024
6328fa9
#7 fix(devops): adjust Main CD pipeline only for main branch
NikitaBuffy Dec 10, 2024
8e49de0
Merge branch 'devops' into 'main' from pull request #33
NikitaBuffy Dec 10, 2024
8829d35
#34 test(frontend): changes for testing CI/CD pipeline
NikitaBuffy Dec 10, 2024
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
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Repo owner
* @NikitaBuffy
56 changes: 56 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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: '21'
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: 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:
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 }}
SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY }}
run: |
cd backend
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 }}
66 changes: 66 additions & 0 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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: |
cd frontend
npm install

- name: Build frontend
run: |
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:
java-version: '17'
distribution: 'temurin'

- 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 }}
SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY }}
run: |
cd frontend
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
23 changes: 23 additions & 0 deletions .github/workflows/main-restrict.yml
Original file line number Diff line number Diff line change
@@ -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
89 changes: 89 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Main CD

on:
pull_request:
types: [closed]
branches:
- main
workflow_dispatch:

jobs:
cd-backend:
if: github.event.pull_request.merged == true && github.event.pull_request.head.ref == 'backend'
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 Backend Artifact
uses: actions/download-artifact@v4
with:
name: backend-jar
path: backend/target/

- 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/[email protected]
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
path: frontend/dist/

- name: Build and Push Frontend Image
run: |
cd frontend
docker build -t nickpominov/lm-frontend:latest .
docker push nickpominov/lm-frontend:latest

- name: Deploy Frontend to Remote Server
uses: appleboy/[email protected]
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-frontend
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@

# Logs
/logs/

# Environment
.env
3 changes: 3 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM amazoncorretto:21-alpine-jdk
COPY target/*.jar lm-backend.jar
ENTRYPOINT ["java", "-jar", "/lm-backend.jar"]
26 changes: 13 additions & 13 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-jpa</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-security</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand All @@ -42,11 +42,11 @@
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>

<!-- <dependency>-->
<!-- <groupId>org.postgresql</groupId>-->
<!-- <artifactId>postgresql</artifactId>-->
<!-- <scope>runtime</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
11 changes: 11 additions & 0 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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}
58 changes: 58 additions & 0 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -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: [email protected]
PGADMIN_DEFAULT_PASSWORD: admin
ports:
- "5050:80"
networks:
- app-network

networks:
app-network:
driver: bridge
Loading
Loading