-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
69 lines (57 loc) · 1.9 KB
/
.gitlab-ci.yml
File metadata and controls
69 lines (57 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
stages:
- build
# - test
- deploy
default:
tags:
- "project"
variables:
DEPLOY_PATH: "/mnt/training-bsb-be"
workflow:
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
variables:
IMAGE_TAG: "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME"
# ENV_FILE: "$ENV_DEV"
# ENV_PATH: "$DEPLOY_PATH/.env/develop/.frontend-jogjalib.env"
COMPOSE_FILE: "docker-compose.prod.yaml"
COMPOSE_SERVICE: "app"
DOCKERFILE: "Dockerfile"
- when: never
############################################ TEMPLATES ############################################
.ssh_template:
image: alpine:3.21
before_script:
- apk update && apk add --no-cache openssh-client
- chmod 400 $ID_RSA
- mkdir -p ~/.ssh && chmod 700 ~/.ssh
- ssh-keyscan -H $SERVER_DEV >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
.docker_login_template:
before_script:
- echo $CI_JOB_TOKEN | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
############################################ BUILD ############################################
deploy:
stage: deploy
needs: []
extends: .ssh_template
script:
- |
# Using $USER_DEV and $SERVER_DEV from global variables
ssh -i $ID_RSA $USER_DEV@$SERVER_DEV "
set -e
echo "Logging into GitLab Registry..."
echo "$CI_JOB_TOKEN" | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
echo "Changing to deployment directory..."
cd "$DEPLOY_PATH"
echo "Pulling code..."
git checkout -- . && git pull
echo "Building Image..."
docker compose -f $COMPOSE_FILE build --no-cache $COMPOSE_SERVICE
echo "Running docker compose for service..."
docker compose -f "$COMPOSE_FILE" up -d --force-recreate "$COMPOSE_SERVICE"
echo "Deployment complete."
"
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
retry: 1