Skip to content

Commit

Permalink
feat: #dev add dev-deploy file and other (#199)
Browse files Browse the repository at this point in the history
* dev deploy preparations

* kodemy.sh deploy file

* fix :#dev-deploy services config fix

* fix :#dev-deploy search config fix

* Create dev-deploy.yml

* Update dev-deploy.yml

* Update dev-deploy.yml

* fix: #dev-deploy script

---------

Co-authored-by: Marcin Bator <[email protected]>
  • Loading branch information
KartVen and marcinbator authored Nov 27, 2024
1 parent 95ad8c7 commit ce2c0f7
Show file tree
Hide file tree
Showing 16 changed files with 159 additions and 88 deletions.
12 changes: 8 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# DataSource
POSTGRES_HOST=localhost
POSTGRES_PORT=5435
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_DB=kodemy
POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=postgres
Expand All @@ -14,9 +14,13 @@ RABBITMQ_USERNAME=rabbitmq
RABBITMQ_PASSWORD=rabbitmq

# Elastic search
ELASTICSEARCH_HOSTS=["http://localhost:9200"]
ELASTICSEARCH_HOSTS=["http://opensearch:9200"]
ELASTICSEARCH_USERNAME=opensearch
ELASTICSEARCH_PASSWORD=opensearch

# Eureka
EUREKA_URL=http://localhost:8761/eureka
EUREKA_URL=http://kodemy-service-registry:8761/eureka/

# Kodemy
FRONTEND_PUBLIC_HOST=http://localhost:3000
GATEWAY_PUBLIC_HOST=http://localhost:8080
24 changes: 24 additions & 0 deletions .github/workflows/dev-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Deploy

on:
push:
branches: [ "dev-deploy" ]

jobs:
build:
runs-on: self-hosted
steps:
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
port: ${{ secrets.REMOTE_PORT }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /home/kodemy/KodemyBackend/
git checkout dev-deploy
git pull || { echo "Error: git pull failed" >&2; exit 1; }
./kodemy.sh
echo "$(date): backend deployed successfully" >> deploy-log.txt
docker system prune -f
Empty file modified commons/gradlew
100644 → 100755
Empty file.
105 changes: 85 additions & 20 deletions docker-compose.stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ services:
postgres:
image: postgres:14.1-alpine
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_USER: ${POSTGRES_USERNAME}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- postgres_vol:/var/lib/postgresql/data
- ./init_schema.sql:/docker-entrypoint-initdb.d/init_schema.sql
ports:
- 5435:${POSTGRES_PORT}
- ${POSTGRES_PORT}:5432
networks:
- kodemy
deploy:
Expand All @@ -17,8 +18,8 @@ services:
rabbitmq:
image: rabbitmq:3.8-management-alpine
environment:
RABBITMQ_DEFAULT_USER: ${RABBITMQ_DEFAULT_USER}
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_DEFAULT_PASS}
RABBITMQ_DEFAULT_USER: ${RABBITMQ_USERNAME}
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_PASSWORD}
volumes:
- rabbitmq_vol:/var/lib/rabbitmq
ports:
Expand All @@ -30,7 +31,7 @@ services:
replicas: 1

opensearch:
image: opensearchproject/opensearch:2.15.0
image: opensearchproject/opensearch:latest
environment:
OPENSEARCH_JAVA_OPTS: "-Xms1024m -Xmx1024m"
cluster.name: kodemy-os-cluster
Expand All @@ -39,23 +40,26 @@ services:
discovery.type: single-node
DISABLE_SECURITY_PLUGIN: "true"
bootstrap.memory_lock: "true"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
# ulimits:
# memlock:
# soft: -1
# hard: -1
# nofile:
# soft: 65536
# hard: 65536
volumes:
- opensearch_vol:/usr/share/opensearch/data
#- ./config/opensearch.yml:/usr/share/opensearch/config/opensearch.yml
ports:
- 9200:9200
- 9600:9600
networks:
- kodemy

opensearch-dashboards:
image: opensearchproject/opensearch-dashboards:2.15.0
image: opensearchproject/opensearch-dashboards:latest
environment:
OPENSEARCH_HOSTS: ${OPENSEARCH_HOSTS}
OPENSEARCH_HOSTS: ${ELASTICSEARCH_HOSTS}
DISABLE_SECURITY_DASHBOARDS_PLUGIN: true
#ELASTICSEARCH_USERNAME: ${ELASTICSEARCH_USERNAME}
#ELASTICSEARCH_PASSWORD: ${ELASTICSEARCH_PASSWORD}
Expand All @@ -75,45 +79,100 @@ services:
deploy:
replicas: 1

kodemy-service-registry:
image: kodemy-service-registry:latest
build:
context: ./kodemy-service-registry
dockerfile: ./Dockerfile
ports:
- "8761:8761"
networks:
- kodemy
deploy:
replicas: 1

kodemy-api-gateway:
image: kodemy-api-gateway:latest
build:
context: ./kodemy-api-gateway
dockerfile: ./Dockerfile
ports:
- "8080:8080"
networks:
- kodemy
environment:
FRONTEND_PUBLIC_HOST: ${FRONTEND_PUBLIC_HOST}
EUREKA_URL: ${EUREKA_URL}
deploy:
replicas: 1
depends_on:
- kodemy-service-registry

kodemy-auth:
image: kodemy-auth:latest
build:
context: ./kodemy-auth
dockerfile: ./Dockerfile
networks:
- kodemy
ports:
- "8081:8080"
environment:
SPRING_DATASOURCE_URL: ${DATASOURCE_URL}?currentSchema=kodemy-auth
SPRING_DATASOURCE_USERNAME: ${POSTGRES_USER}
SPRING_DATASOURCE_USERNAME: ${POSTGRES_USERNAME}
SPRING_DATASOURCE_PASSWORD: ${POSTGRES_PASSWORD}
FRONTEND_PUBLIC_HOST: ${FRONTEND_PUBLIC_HOST}
GATEWAY_PUBLIC_HOST: ${GATEWAY_PUBLIC_HOST}
EUREKA_URL: ${EUREKA_URL}
deploy:
replicas: 1
depends_on:
- postgres
- redis
- kodemy-service-registry

kodemy-backend:
image: kodemy-backend:latest
build:
context: ./kodemy-backend
dockerfile: ./Dockerfile
networks:
- kodemy
ports:
- "8082:8080"
environment:
SPRING_DATASOURCE_URL: ${DATASOURCE_URL}?currentSchema=kodemy-backend
SPRING_DATASOURCE_USERNAME: ${POSTGRES_USERNAME}
SPRING_DATASOURCE_PASSWORD: ${POSTGRES_PASSWORD}
SPRING_RABBITMQ_HOST: ${RABBITMQ_HOST}
SPRING_RABBITMQ_PORT: ${RABBITMQ_PORT}
SPRING_RABBITMQ_USERNAME: ${RABBITMQ_USERNAME}
SPRING_RABBITMQ_PASSWORD: ${RABBITMQ_PASSWORD}
EUREKA_URL: ${EUREKA_URL}
deploy:
replicas: 1
depends_on:
- postgres
- rabbitmq

kodemy-notification:
image: kodemy-notification:latest
build:
context: ./kodemy-notification
dockerfile: ./Dockerfile
networks:
- kodemy
ports:
- "8084:8080"
environment:
SPRING_DATASOURCE_URL: ${DATASOURCE_URL}?currentSchema=kodemy-backend
SPRING_DATASOURCE_USERNAME: ${POSTGRES_USER}
SPRING_DATASOURCE_USERNAME: ${POSTGRES_USERNAME}
SPRING_DATASOURCE_PASSWORD: ${POSTGRES_PASSWORD}
SPRING_RABBITMQ_HOST: ${RABBITMQ_HOST}
SPRING_RABBITMQ_PORT: ${RABBITMQ_PORT}
SPRING_RABBITMQ_USERNAME: ${RABBITMQ_DEFAULT_USER}
SPRING_RABBITMQ_PASSWORD: ${RABBITMQ_DEFAULT_PASS}
SPRING_RABBITMQ_USERNAME: ${RABBITMQ_USERNAME}
SPRING_RABBITMQ_PASSWORD: ${RABBITMQ_PASSWORD}
EUREKA_URL: ${EUREKA_URL}
deploy:
replicas: 1
depends_on:
Expand All @@ -122,13 +181,19 @@ services:

kodemy-search:
image: kodemy-search:latest
build:
context: ./kodemy-search
dockerfile: ./Dockerfile
networks:
- kodemy
ports:
- "8083:8080"
environment:
SPRING_RABBITMQ_HOST: ${RABBITMQ_HOST}
SPRING_RABBITMQ_PORT: ${RABBITMQ_PORT}
SPRING_RABBITMQ_USERNAME: ${RABBITMQ_DEFAULT_USER}
SPRING_RABBITMQ_PASSWORD: ${RABBITMQ_DEFAULT_PASS}
SPRING_RABBITMQ_USERNAME: ${RABBITMQ_USERNAME}
SPRING_RABBITMQ_PASSWORD: ${RABBITMQ_PASSWORD}
EUREKA_URL: ${EUREKA_URL}
deploy:
replicas: 1
depends_on:
Expand Down
3 changes: 3 additions & 0 deletions init_schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE SCHEMA IF NOT EXISTS "kodemy-auth";
CREATE SCHEMA IF NOT EXISTS "kodemy-backend";
CREATE SCHEMA IF NOT EXISTS "kodemy-notification";
14 changes: 2 additions & 12 deletions kodemy-api-gateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
FROM gradle:8.8.0-jdk17 AS gradle_build
COPY --chown=gradle:gradle build.gradle settings.gradle /home/gradle/project/
COPY --chown=gradle:gradle gradle /home/gradle/project/gradle
WORKDIR /home/gradle/project
RUN gradle dependencies --no-daemon

COPY --chown=gradle:gradle . /home/gradle/project
WORKDIR /home/gradle/project
RUN gradle build --no-daemon -x test

FROM openjdk:17.0.2-slim-buster AS runtime
EXPOSE 8080
COPY --from=gradle_build /home/gradle/project/build/libs/*.jar /app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
COPY build/libs/kodemy-api-gateway.jar /app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
1 change: 1 addition & 0 deletions kodemy-api-gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ network:
auth: http://kodemy-auth:8080
backend: http://kodemy-backend:8080
search: http://kodemy-search:8080
front: ${FRONTEND_PUBLIC_HOST}

logging:
level:
Expand Down
14 changes: 2 additions & 12 deletions kodemy-auth/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
FROM gradle:8.8.0-jdk17 AS gradle_build
COPY --chown=gradle:gradle build.gradle settings.gradle /home/gradle/project/
COPY --chown=gradle:gradle gradle /home/gradle/project/gradle
WORKDIR /home/gradle/project
RUN gradle dependencies --no-daemon

COPY --chown=gradle:gradle . /home/gradle/project
WORKDIR /home/gradle/project
RUN gradle build --no-daemon -x test

FROM openjdk:17.0.2-slim-buster AS runtime
EXPOSE 8080
COPY --from=gradle_build /home/gradle/project/build/libs/*.jar /app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
COPY build/libs/kodemy-auth.jar /app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
9 changes: 6 additions & 3 deletions kodemy-auth/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ spring:
banner.location: classpath:banner.txt
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://postgres/kodemy?currentSchema=kodemy-auth
username: postgres
password: postgres
url: ${SPRING_DATASOURCE_URL}
username: ${SPRING_DATASOURCE_USERNAME}
password: ${SPRING_DATASOURCE_PASSWORD}
hikari:
schema: kodemy-auth
data:
redis:
host: redis
Expand All @@ -18,6 +20,7 @@ spring:
show-sql: true
properties:
hibernate.types.print.banner: false

liquibase:
change-log: classpath:/db/changelog/db.changelog-root.xml
contexts: prod
Expand Down
14 changes: 2 additions & 12 deletions kodemy-backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
FROM gradle:8.8.0-jdk17 AS gradle_build
COPY --chown=gradle:gradle build.gradle settings.gradle /home/gradle/project/
COPY --chown=gradle:gradle gradle /home/gradle/project/gradle
WORKDIR /home/gradle/project
RUN gradle dependencies --no-daemon

COPY --chown=gradle:gradle . /home/gradle/project
WORKDIR /home/gradle/project
RUN gradle build --no-daemon -x test

FROM openjdk:17.0.2-slim-buster AS runtime
EXPOSE 8080
COPY --from=gradle_build /home/gradle/project/build/libs/*.jar /app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
COPY build/libs/kodemy-backend.jar /app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
14 changes: 2 additions & 12 deletions kodemy-notification/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
FROM gradle:8.8.0-jdk17 AS gradle_build
COPY --chown=gradle:gradle build.gradle settings.gradle /home/gradle/project/
COPY --chown=gradle:gradle gradle /home/gradle/project/gradle
WORKDIR /home/gradle/project
RUN gradle dependencies --no-daemon

COPY --chown=gradle:gradle . /home/gradle/project
WORKDIR /home/gradle/project
RUN gradle build --no-daemon -x test

FROM openjdk:17.0.2-slim-buster AS runtime
EXPOSE 8080
COPY --from=gradle_build /home/gradle/project/build/libs/*.jar /app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
COPY build/libs/kodemy-notification.jar /app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
14 changes: 2 additions & 12 deletions kodemy-search/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
FROM gradle:8.8.0-jdk17 AS gradle_build
COPY --chown=gradle:gradle build.gradle settings.gradle /home/gradle/project/
COPY --chown=gradle:gradle gradle /home/gradle/project/gradle
WORKDIR /home/gradle/project
RUN gradle dependencies --no-daemon

COPY --chown=gradle:gradle . /home/gradle/project
WORKDIR /home/gradle/project
RUN gradle build --no-daemon -x test

FROM openjdk:17.0.2-slim-buster AS runtime
EXPOSE 8080
COPY --from=gradle_build /home/gradle/project/build/libs/*.jar /app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
COPY build/libs/kodemy-search.jar /app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
4 changes: 4 additions & 0 deletions kodemy-service-registry/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM openjdk:17.0.2-slim-buster AS runtime
EXPOSE 8761
COPY build/libs/kodemy-service-registry.jar /app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
1 change: 0 additions & 1 deletion kodemy-service-registry/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ plugins {
}

group = 'pl.sknikod'
version = '0.0.1-SNAPSHOT'

java {
toolchain {
Expand Down
Empty file modified kodemy-service-registry/gradlew
100644 → 100755
Empty file.
Loading

0 comments on commit ce2c0f7

Please sign in to comment.