ci: build image and deploy via docker compose

This commit is contained in:
Konturai DevOps
2026-04-30 02:04:21 +05:00
parent 3918ce666e
commit 411cf44742
3 changed files with 57 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
stages:
- build
- deploy
variables:
DOCKER_TLS_CERTDIR: ""
build:image:
stage: build
image: docker:27
services:
- name: docker:27-dind
command: ["--tls=false"]
rules:
- if: $CI_COMMIT_BRANCH
script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
- docker build -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA" -t "$CI_REGISTRY_IMAGE:latest" .
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA"
- docker push "$CI_REGISTRY_IMAGE:latest"
deploy:prod:
stage: deploy
image: alpine:3.20
needs: ["build:image"]
rules:
- if: $CI_COMMIT_BRANCH == "main"
before_script:
- apk add --no-cache openssh-client
- mkdir -p ~/.ssh
- echo "$DEPLOY_SSH_PRIVATE_KEY" | tr -d "\r" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- ssh-keyscan -H "$DEPLOY_HOST" >> ~/.ssh/known_hosts
script:
- ssh "$DEPLOY_USER@$DEPLOY_HOST" "cd '$DEPLOY_PATH' && ./deploy/deploy.sh '$CI_REGISTRY_IMAGE' '$CI_COMMIT_SHA'"