diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..ba5c34b --- /dev/null +++ b/.gitlab-ci.yml @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..08930d0 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/deployments/local/docker-compose.yaml b/deployments/local/docker-compose.yaml index a1a2667..2f80b77 100644 --- a/deployments/local/docker-compose.yaml +++ b/deployments/local/docker-compose.yaml @@ -1,22 +1,12 @@ -version: '3.8' - services: - zookeeper: - image: wurstmeister/zookeeper - ports: - - "2181:2181" - - kafka: - image: wurstmeister/kafka - ports: - - "9092:9092" + postgres: + image: postgres + restart: always environment: - KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092 - KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT - KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 - KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 - KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092 - KAFKA_CREATE_TOPICS: "test-topic:1:1" - volumes: - - /var/run/docker.sock:/var/run/docker.sock \ No newline at end of file + POSTGRES_PASSWORD: Redalert2 + POSTGRES_USER: squiz + POSTGRES_DB: squiz + app: + image: penahub.gitlab.yandexcloud.net:5050/backend/squiz:latest + ports: + - 1488:1488 diff --git a/deployments/main/docker-compose.yaml b/deployments/main/docker-compose.yaml index e69de29..46ada01 100644 --- a/deployments/main/docker-compose.yaml +++ b/deployments/main/docker-compose.yaml @@ -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 diff --git a/deployments/main/staging/docker-compose.yaml b/deployments/main/staging/docker-compose.yaml new file mode 100644 index 0000000..693c593 --- /dev/null +++ b/deployments/main/staging/docker-compose.yaml @@ -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 + diff --git a/deployments/staging/docker-compose.yaml b/deployments/staging/docker-compose.yaml index e69de29..94b71f3 100644 --- a/deployments/staging/docker-compose.yaml +++ b/deployments/staging/docker-compose.yaml @@ -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 diff --git a/deployments/test/docker-compose.yaml b/deployments/test/docker-compose.yaml index 8c81c0e..b66713c 100644 --- a/deployments/test/docker-compose.yaml +++ b/deployments/test/docker-compose.yaml @@ -1,15 +1,102 @@ -version: '3.8' - +version: '3' services: - mongo: - image: mongo - ports: - - "27020:27017" + test-postgres: + image: postgres environment: - - MONGO_INITDB_ROOT_USERNAME=test - - MONGO_INITDB_ROOT_PASSWORD=test - - MONGO_INITDB_AUTH_MECHANISM=SCRAM-SHA-1 + POSTGRES_PASSWORD: Redalert2 + POSTGRES_USER: squiz + POSTGRES_DB: squiz 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: - mongo_data: \ No newline at end of file + test-minio: + test-postgres: + test-mongodb: + test-mongoconfdb: diff --git a/tools/migrate b/tools/migrate new file mode 100644 index 0000000..573af5c Binary files /dev/null and b/tools/migrate differ