From 29a664fdcb220fa07ab1ed9ed2e7d0949f85993f Mon Sep 17 00:00:00 2001 From: Grant Date: Wed, 25 Dec 2024 23:41:21 -0700 Subject: [PATCH] Add gitlab-ci --- .gitlab-ci.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..848aa81 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,34 @@ +stages: + - publish + - deploy + +variables: + REGISTRY: registry.sc07.dev + IMAGE_NAME: $GITLAB_USER_LOGIN/$CI_PROJECT_NAME:edge + +publish: + image: docker + stage: publish + services: + - docker:dind + before_script: + - echo $PAT | docker login $REGISTRY -u $GITLAB_USER_LOGIN --password-stdin + script: + - docker build . --tag $REGISTRY/$IMAGE_NAME + - docker push $REGISTRY/$IMAGE_NAME + +deploy: + image: ubuntu:latest + stage: deploy + only: + - main + before_script: + - apt-get -yq update + - apt-get -yqq install ssh + - install -m 600 -D /dev/null ~/.ssh/id_rsa + - echo "$SSH_PRIVATE_KEY" | base64 -d > ~/.ssh/id_rsa + - ssh-keyscan -H $SSH_HOST > ~/.ssh/known_hosts + script: + - ssh $SSH_USER@$SSH_HOST "cd $WORK_DIR && docker compose pull && docker compose up -d && exit" + after_script: + - rm -rf ~/.ssh -- GitLab