ci: deploy preparations and create migrate stage

This commit is contained in:
skeris 2024-05-13 22:40:29 +03:00
parent f071cfaf24
commit ac65e5ef3d
8 changed files with 229 additions and 31 deletions

48
.gitlab-ci.yml Normal file

@ -0,0 +1,48 @@
include:
- project: "devops/pena-continuous-integration"
file: "/templates/docker/build-template.gitlab-ci.yml"
- project: "devops/pena-continuous-integration"
file: "/templates/docker/deploy-template.gitlab-ci.yml"
stages:
- build
- migrate
- deploy
build-app:
stage: build
extends: .build_template
rules:
- if: "$CI_COMMIT_BRANCH == $STAGING_BRANCH || $CI_COMMIT_BRANCH == $PRODUCTION_BRANCH"
script:
- docker build -t $CI_REGISTRY_IMAGE/$CI_COMMIT_BRANCH:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID --build-arg GITLAB_TOKEN=$GITLAB_TOKEN $CI_PROJECT_DIR
- docker push $CI_REGISTRY_IMAGE/$CI_COMMIT_BRANCH:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID
migrate-staging:
stage: migrate
rules:
- if: "$CI_COMMIT_BRANCH == $STAGING_BRANCH"
script:
- git clone git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@penahub.gitlab.yandexcloud.net:backend/quiz/common.git
- ls
- ./tools/migrate -source file://dal/schema -database postgres://squiz:Redalert2@10.8.0.5:5433/database_name?sslmode=disable
deploy-staging:
stage: deploy
tags:
- staging
extends: .deploy_template
rules:
- if: "$CI_COMMIT_BRANCH == $STAGING_BRANCH"
after_script:
- docker ps -a
deploy-prod:
stage: deploy
tags:
- prod
extends: .deploy_template
rules:
- if: "$CI_COMMIT_BRANCH == $PRODUCTION_BRANCH"
after_script:
- ls

17
Dockerfile Normal file

@ -0,0 +1,17 @@
FROM golang:alpine as build
WORKDIR /app
RUN apk add git
COPY . .
ARG GITLAB_TOKEN
ENV GOPRIVATE=penahub.gitlab.yandexcloud.net/backend/penahub_common
RUN git config --global url."https://buildToken:glpat-axA8ttckx3aPf_xd2Dym@penahub.gitlab.yandexcloud.net/".insteadOf "https://penahub.gitlab.yandexcloud.net/"
RUN go mod download
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o amocrm
FROM alpine as prod
COPY --from=build /app/amocrm .
COPY --from=build /app/schema /schema
EXPOSE 1488
ENV IS_PROD_LOG=false
ENV IS_PROD=false
CMD ["/amocrm"]

@ -1,22 +1,12 @@
version: '3.8'
services: services:
zookeeper: postgres:
image: wurstmeister/zookeeper image: postgres
ports: restart: always
- "2181:2181"
kafka:
image: wurstmeister/kafka
ports:
- "9092:9092"
environment: environment:
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092 POSTGRES_PASSWORD: Redalert2
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT POSTGRES_USER: squiz
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT POSTGRES_DB: squiz
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 app:
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 image: penahub.gitlab.yandexcloud.net:5050/backend/squiz:latest
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092 ports:
KAFKA_CREATE_TOPICS: "test-topic:1:1" - 1488:1488
volumes:
- /var/run/docker.sock:/var/run/docker.sock

@ -0,0 +1,19 @@
services:
core:
hostname: squiz-core
container_name: squiz-core
image: $CI_REGISTRY_IMAGE/main-core:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID
tty: true
environment:
HUB_ADMIN_URL: 'http://10.8.0.8:59303'
IS_PROD_LOG: 'false'
IS_PROD: 'false'
PORT: 1488
PUBLIC_ACCESS_SECRET_KEY: $JWT_PUBLIC_KEY
PG_CRED: 'host=10.8.0.9 port=5433 user=squiz password=Redalert2 dbname=squiz sslmode=disable'
AUTH_URL: 'http://10.8.0.8:59300/user'
PUBLIC_KEY: $PEM_PUB_USERID
PRIVATE_KEY: $PEM_PRIV_USERID
REDIRECT_URL: 'https://quiz.pena.digital'
ports:
- 10.8.0.9:1488:1488

@ -0,0 +1,17 @@
services:
core:
hostname: squiz-core
container_name: squiz-core
image: $CI_REGISTRY_IMAGE/core:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID
tty: true
environment:
HUB_ADMIN_URL: 'http://10.6.0.11:59303'
IS_PROD_LOG: 'false'
IS_PROD: 'false'
PORT: 1488
PUBLIC_ACCESS_SECRET_KEY: $JWT_PUBLIC_KEY
PG_CRED: 'host=10.6.0.23 port=5433 user=squiz password=Redalert2 dbname=squiz sslmode=disable'
AUTH_URL: 'http://10.6.0.11:59300/user'
ports:
- 1488:1488

@ -0,0 +1,20 @@
services:
amocrm:
hostname: squiz-amocrm
container_name: squiz-amocrm
image: $CI_REGISTRY_IMAGE/staging:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID
tty: true
environment:
HUB_ADMIN_URL: 'http://10.8.0.6:59303'
IS_PROD_LOG: 'false'
IS_PROD: 'false'
PORT: 1488
PUBLIC_ACCESS_SECRET_KEY: $JWT_PUBLIC_KEY
PG_CRED: 'host=10.8.0.5 port=5433 user=squiz password=Redalert2 dbname=squiz sslmode=disable'
PUBLIC_KEY: $PEM_PUB_USERID
PRIVATE_KEY: $PEM_PRIV_USERID
KAFKA_BROKERS: 10.8.0.6:9092
KAFKA_TOPIC: "mailnotifier"
GRPC_HOST: "0.0.0.0"
ports:
- 10.8.0.5:1490:1488

@ -1,15 +1,102 @@
version: '3.8' version: '3'
services: services:
mongo: test-postgres:
image: mongo image: postgres
ports:
- "27020:27017"
environment: environment:
- MONGO_INITDB_ROOT_USERNAME=test POSTGRES_PASSWORD: Redalert2
- MONGO_INITDB_ROOT_PASSWORD=test POSTGRES_USER: squiz
- MONGO_INITDB_AUTH_MECHANISM=SCRAM-SHA-1 POSTGRES_DB: squiz
volumes: volumes:
- mongo_data:/data/db - test-postgres:/var/lib/postgresql/data
ports:
- 35432:5432
networks:
- penatest
healthcheck:
test: pg_isready -U squiz
interval: 2s
timeout: 2s
retries: 10
# need update!
# test-pena-auth-service:
# image: penahub.gitlab.yandexcloud.net:5050/pena-services/pena-auth-service:staging.872
# container_name: test-pena-auth-service
# init: true
# env_file: auth.env.test
# healthcheck:
# test: wget -T1 --spider http://localhost:8000/user
# interval: 2s
# timeout: 2s
# retries: 5
# environment:
# - DB_HOST=test-pena-auth-db
# - DB_PORT=27017
# - ENVIRONMENT=staging
# - HTTP_HOST=0.0.0.0
# - HTTP_PORT=8000
# - DB_USERNAME=test
# - DB_PASSWORD=test
# - DB_NAME=admin
# - DB_AUTH=admin
# # ports:
# # - 8000:8000
# depends_on:
# - test-pena-auth-db
# # - pena-auth-migration
# networks:
# - penatest
#
# test-pena-auth-db:
# container_name: test-pena-auth-db
# init: true
# image: "mongo:6.0.3"
# command: mongod --quiet --logpath /dev/null
# volumes:
# - test-mongodb:/data/db
# - test-mongoconfdb:/data/configdb
# environment:
# MONGO_INITDB_ROOT_USERNAME: test
# MONGO_INITDB_ROOT_PASSWORD: test
# # ports:
# # - 27017:27017
# networks:
# - penatest
test-minio:
container_name: test-minio
init: true
image: quay.io/minio/minio
volumes:
- test-minio:/data
command: [ "minio", "--quiet", "server", "/data" ]
networks:
- penatest
test-squiz:
container_name: test-squiz
init: true
build:
context: ../..
dockerfile: TestsDockerfile
depends_on:
test-postgres:
condition: service_healthy
# test-pena-auth-service:
# condition: service_healthy
# volumes:
# - ./../..:/app:ro
# command: [ "go", "test", "./tests", "-run", "TestFoo" ]
command: [ "go", "test", "-parallel", "1", "./tests" ]
networks:
- penatest
networks:
penatest:
volumes: volumes:
mongo_data: test-minio:
test-postgres:
test-mongodb:
test-mongoconfdb:

BIN
tools/migrate Normal file

Binary file not shown.