From a004bd2fd2233fde10d0a2f19934206a0ff64fd4 Mon Sep 17 00:00:00 2001 From: hizmailovich Date: Thu, 7 Mar 2024 15:40:02 +0300 Subject: [PATCH] Resolved #6 --- .rultor.yml | 33 ++++++++++++++++++-------- scripts/deploy/default.conf | 12 ++++++++++ scripts/deploy/setup.sh | 19 +++++++++++++++ scripts/release/docker-compose.yml | 37 ++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 scripts/deploy/default.conf create mode 100644 scripts/deploy/setup.sh create mode 100644 scripts/release/docker-compose.yml diff --git a/.rultor.yml b/.rultor.yml index 61dae25..9700a41 100644 --- a/.rultor.yml +++ b/.rultor.yml @@ -4,6 +4,9 @@ docker: image: l3r8y/rultor-image:1.0.3 assets: ghcr.txt: tracehubpm/secrets#assets/ghcr.txt + creds.txt: tracehubpm/secrets#assets/creds.txt + pmo.env: tracehubpm/secrets#assets/pmo.env + keycloak.env: tracehubpm/secrets#assets/keycloak.env merge: script: | mvn clean install --errors @@ -11,14 +14,26 @@ release: sensitive: - ghcr.txt script: | - [[ "${tag}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9_]+)?$ ]] || exit -1 - mvn versions:set "-DnewVersion=${tag}" - git commit -am "${tag}" + [[ "${TAG}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9_]+)?$ ]] || exit -1 + mvn versions:set "-DnewVersion=${TAG}" + git commit -am "${TAG}" mvn clean install - docker build -t ghcr.io/tracehubpm/pmo:${tag} . + docker build -t ghcr.io/tracehubpm/pmo:${TAG} . cat ../ghcr.txt | docker login ghcr.io --username h1alexbel --password-stdin - docker push ghcr.io/tracehubpm/pmo:${tag} -# @todo #2:90min Create deploy script for rultor configuration. -# We should create deploy script that will deliver our Java software -# into some target platform. For now, we assuming that it will be -# Cloud VM with public IP, and SSH connection. + docker push ghcr.io/tracehubpm/pmo:${TAG} + sudo apt-get -y install sshpass + echo ${TAG} >> /home/r/repo/scripts/release/tag.txt + sshpass -f ../creds.txt scp -r /home/r/repo/scripts/release root@${IP}:~/ + sshpass -f ../creds.txt scp ../pmo.env root@${IP}:~/release/pmo.env + sshpass -f ../creds.txt scp ../keycloak.env root@${IP}:~/release/keycloak.env + sshpass -f ../creds.txt ssh -o StrictHostKeyChecking=no root@${IP} + cd release + TAG=$(cat tag.txt) + TAG=${TAG} docker-compose up -d --build +deploy: + script: | + sudo apt-get -y install sshpass + sshpass -f ../creds.txt scp -r /home/r/repo/scripts/deploy root@${IP}:~/ + sshpass -f ../creds.txt ssh -o StrictHostKeyChecking=no root@${IP} + cd deploy + sh setup.sh \ No newline at end of file diff --git a/scripts/deploy/default.conf b/scripts/deploy/default.conf new file mode 100644 index 0000000..050cce9 --- /dev/null +++ b/scripts/deploy/default.conf @@ -0,0 +1,12 @@ +server { + listen 80; + + server_name pmo.tracehub.git; + + location /realms/ { + proxy_pass http://localhost:8090; + } + location / { + proxy_pass http://localhost:8080; + } +} \ No newline at end of file diff --git a/scripts/deploy/setup.sh b/scripts/deploy/setup.sh new file mode 100644 index 0000000..41be0c1 --- /dev/null +++ b/scripts/deploy/setup.sh @@ -0,0 +1,19 @@ +sudo apt-get update && sudo apt-get -y upgrade +sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - +sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" +sudo apt-get -y install docker-ce +sudo systemctl status docker +sudo apt-get -y install curl gnupg2 ca-certificates lsb-release ubuntu-keyring +curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \ + | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null +gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg +echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \ +http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" \ + | sudo tee /etc/apt/sources.list.d/nginx.list +echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \ + | sudo tee /etc/apt/preferences.d/99nginx +sudo apt-get -y install nginx +sudo mv default.conf /etc/nginx/conf.d/default.conf +sudo systemctl restart nginx +sudo systemctl status nginx diff --git a/scripts/release/docker-compose.yml b/scripts/release/docker-compose.yml new file mode 100644 index 0000000..2a20e48 --- /dev/null +++ b/scripts/release/docker-compose.yml @@ -0,0 +1,37 @@ +version: '3.9' + +services: + keycloak: + image: quay.io/keycloak/keycloak:23.0.2 + container_name: keycloak + environment: + KC_DB: ${KC_DB} + KC_DB_URL_HOST: ${KC_DB_URL_HOST} + KC_DB_USERNAME: ${KC_DB_USERNAME} + KC_DB_PASSWORD: ${KC_DB_PASSWORD} + KEYCLOAK_ADMIN: ${KEYCLOAK_ADMIN} + KEYCLOAK_ADMIN_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD} + ports: + - '8090:8090' + networks: + - pmo + command: start --import-realm --http-port=8090 + volumes: + - ./realm-export.json:/opt/keycloak/data/import/realm-export.json + env_file: + - keycloak.env + app: + container_name: tracehub-pmo + image: ghcr.io/tracehubpm/pmo:${TAG} + ports: + - '8080:8080' + depends_on: + - keycloak + networks: + - pmo + env_file: + - pmo.env + +networks: + pmo: + driver: bridge \ No newline at end of file