mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2025-12-16 12:33:17 +00:00
36 lines
1.4 KiB
YAML
36 lines
1.4 KiB
YAML
stages:
|
|
- build
|
|
- deploy
|
|
|
|
variables:
|
|
IMAGE_NAME: registry.gitlab.com/cargo-solutions/api
|
|
IMAGE_TAG: ${CI_COMMIT_SHA}
|
|
|
|
build:
|
|
stage: build
|
|
image: docker:stable
|
|
services:
|
|
- docker:dind
|
|
script:
|
|
- sudo apt-get update && sudo apt-get install -y python3-pip python3-dev libffi-dev libssl-dev gcc libc6-dev make && sudo rm -rf /var/lib/apt/lists/*
|
|
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY_IMAGE
|
|
- docker build -t api:latest .
|
|
- docker tag api registry.gitlab.com/r-et-d/todo-api:latest
|
|
- docker tag api:latest registry.gitlab.com/r-et-d/todo-api:${CI_COMMIT_SHA}
|
|
- docker push registry.gitlab.com/r-et-d/todo-api:latest
|
|
- docker push registry.gitlab.com/r-et-d/todo-api:${CI_COMMIT_SHA}
|
|
only:
|
|
- master
|
|
|
|
deploy:
|
|
stage: deploy
|
|
image: ubuntu:20.04
|
|
script:
|
|
- export DEBIAN_FRONTEND=noninteractive
|
|
- sudo apt-get update -y
|
|
- sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common openssh-client
|
|
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' > id_rsa
|
|
- sudo chmod 600 id_rsa
|
|
- ssh -i id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $SSH_USER@$SSH_HOST "\cd /home/ci && \git pull && \cd && \docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $IMAGE_NAME && \bash /home/ci/docker-compose restart"
|
|
only:
|
|
- master |