diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 010a140..eeb5118 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,7 +3,7 @@ stages: - deploy build: - image: maven:3.8.4-openjdk-17 + image: maven:3.8.6-eclipse-temurin-17 stage: build variables: MAVEN_OPTS: "-Dmaven.repo.local=./.m2/repository" @@ -29,6 +29,5 @@ docker-build: before_script: - echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY --username $CI_REGISTRY_USER --password-stdin script: - - cd gitlab-app - docker buildx create --use - docker buildx build --push --platform linux/amd64,linux/arm64/v8 -t "$CI_REGISTRY_IMAGE:latest" -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" . \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..881ac59 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +FROM eclipse-temurin:17 as app-build +ENV RELEASE=17 + +WORKDIR /opt/build +COPY ./gitlab-app/target/gitlab-notification.jar ./application.jar + +RUN java -Djarmode=layertools -jar application.jar extract +RUN $JAVA_HOME/bin/jlink \ + --add-modules `jdeps --ignore-missing-deps -q -recursive --multi-release ${RELEASE} --print-module-deps -cp 'dependencies/BOOT-INF/lib/*' application.jar`,jdk.crypto.cryptoki \ + --strip-java-debug-attributes \ + --no-man-pages \ + --no-header-files \ + --compress=2 \ + --output jdk + +FROM debian:buster-slim + +ARG BUILD_PATH=/opt/build +ENV JAVA_HOME=/opt/jdk +ENV PATH "${JAVA_HOME}/bin:${PATH}" +ENV TELEGRAM_PERSON_ID=TELEGRAM_PERSON_ID DATASOURCE_URL=DATASOURCE_URL \ + DATASOURCE_PASSWORD=DATASOURCE_PASSWORD DATASOURCE_USERNAME=DATASOURCE_USERNAME \ + GITLAB_PERSONAL_TOKEN=GITLAB_PERSONAL_TOKEN TELEGRAM_BOT_TOKEN=TELEGRAM_BOT_TOKEN \ + TELEGRAM_BOT_USERNAME=TELEGRAM_BOT_USERNAME GITLAB_URL=GITLAB_URL GITLAB_REPLACE_URL=GITLAB_REPLACE_URL + +RUN groupadd --gid 1000 spring-app \ + && useradd --uid 1000 --gid spring-app --shell /bin/bash --create-home spring-app + +USER spring-app:spring-app +WORKDIR /opt/workspace + +COPY --from=app-build $BUILD_PATH/jdk $JAVA_HOME +COPY --from=app-build $BUILD_PATH/spring-boot-loader/ ./ +COPY --from=app-build $BUILD_PATH/dependencies/ ./ +COPY --from=app-build $BUILD_PATH/application/ ./ + +ENTRYPOINT java -DTELEGRAM_BOT_USERNAME=$TELEGRAM_BOT_USERNAME -DTELEGRAM_BOT_TOKEN=$TELEGRAM_BOT_TOKEN -DTELEGRAM_PERSON_ID=$TELEGRAM_PERSON_ID -DDATASOURCE_URL=$DATASOURCE_URL -DDATASOURCE_PASSWORD=$DATASOURCE_PASSWORD -DDATASOURCE_USERNAME=$DATASOURCE_USERNAME -DGITLAB_PERSONAL_TOKEN=$GITLAB_PERSONAL_TOKEN -DGITLAB_URL=$GITLAB_URL -DGITLAB_REPLACE_URL=$GITLAB_REPLACE_URL org.springframework.boot.loader.JarLauncher \ No newline at end of file diff --git a/gitlab-app/Dockerfile b/Dockerfile-old similarity index 90% rename from gitlab-app/Dockerfile rename to Dockerfile-old index 06b6cf3..b54c4db 100644 --- a/gitlab-app/Dockerfile +++ b/Dockerfile-old @@ -1,12 +1,12 @@ -FROM openjdk:17.0.2-jdk-slim-buster -MAINTAINER uPagge +FROM amazoncorretto:17.0.5 +MAINTAINER uPagge RUN apt upgrade && addgroup gitlabbot --disabled-password && \ adduser gitlabbot --ingroup gitlabbot && \ mkdir -p /bot && \ chown -R gitlabbot:gitlabbot /bot WORKDIR /bot USER gitlabbot:gitlabbot -COPY target/gitlab-notification.jar app.jar +COPY gitlab-app/target/gitlab-notification.jar app.jar ENV TELEGRAM_PERSON_ID=TELEGRAM_PERSON_ID DATASOURCE_URL=DATASOURCE_URL \ DATASOURCE_PASSWORD=DATASOURCE_PASSWORD DATASOURCE_USERNAME=DATASOURCE_USERNAME \ GITLAB_PERSONAL_TOKEN=GITLAB_PERSONAL_TOKEN TELEGRAM_BOT_TOKEN=TELEGRAM_BOT_TOKEN \ diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml new file mode 100644 index 0000000..f28cabc --- /dev/null +++ b/docker-compose-dev.yml @@ -0,0 +1,29 @@ +version: '3.3' + +services: + + database: + image: postgres:15.1-alpine + environment: + POSTGRES_DB: "gitlab_bot" + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: ${DATASOURCE_PASSWORD} + volumes: + - database:/var/lib/postgresql/data/ + + gitlab-bot: + build: . + depends_on: + - database + environment: + TELEGRAM_BOT_TOKEN: ${TELEGRAM_BOT_TOKEN} + TELEGRAM_BOT_USERNAME: ${TELEGRAM_BOT_USERNAME} + GITLAB_PERSONAL_TOKEN: ${GITLAB_PERSONAL_TOKEN} + TELEGRAM_PERSON_ID: ${TELEGRAM_PERSON_ID} + GITLAB_URL: ${GITLAB_URL} + DATASOURCE_URL: "jdbc:postgresql://database:5432/gitlab_bot" + DATASOURCE_USERNAME: "postgres" + DATASOURCE_PASSWORD: ${DATASOURCE_PASSWORD} + +volumes: + database: \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9562991 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,31 @@ +version: '3.3' + +services: + + database: + image: postgres:15.1-alpine + restart: always + environment: + POSTGRES_DB: "gitlab_bot" + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: ${DATASOURCE_PASSWORD} + volumes: + - database:/var/lib/postgresql/data/ + + gitlab-bot: + image: upagge/gitlab-telegram-notify:latest + restart: always + depends_on: + - database + environment: + TELEGRAM_BOT_TOKEN: ${TELEGRAM_BOT_TOKEN} + TELEGRAM_BOT_USERNAME: ${TELEGRAM_BOT_USERNAME} + GITLAB_PERSONAL_TOKEN: ${GITLAB_PERSONAL_TOKEN} + TELEGRAM_PERSON_ID: ${TELEGRAM_PERSON_ID} + GITLAB_URL: ${GITLAB_URL} + DATASOURCE_URL: "jdbc:postgresql://database:5432/gitlab_bot" + DATASOURCE_USERNAME: "postgres" + DATASOURCE_PASSWORD: ${DATASOURCE_PASSWORD} + +volumes: + database: \ No newline at end of file diff --git a/gitlab-app/src/main/resources/application.yml b/gitlab-app/src/main/resources/application.yml index d0c4dd7..f991e5d 100644 --- a/gitlab-app/src/main/resources/application.yml +++ b/gitlab-app/src/main/resources/application.yml @@ -1,5 +1,3 @@ -server: - port: 8018 spring: datasource: url: ${DATASOURCE_URL} diff --git a/pom.xml b/pom.xml index eb0f676..b9eb7b5 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,7 @@ UTF-8 UTF-8 - 0.0.37 + 0.0.38 2.2