Files
material-api/.gitlab-ci.yml
2024-05-29 10:21:31 +08:00

54 lines
1.5 KiB
YAML

stages:
- build
- deploy
variables:
DEPLOY_PATH: '/opt/app/material_api'
DEPLOY_DEV_HOST_IP: '192.168.137.123'
PIP_CACHE_DIR: "/cache/pip"
SSH_OPTS: "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
FF_NETWORK_PER_BUILD: "true"
.import_ssh_key: &import_ssh_key
before_script:
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- echo "${DEPLOY_SSH_KEY}" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
.cache: &cache
key: "${CI_PROJECT_PATH}-${CI_COMMIT_REF_SLUG}"
paths:
- home/
build:
stage: build
image: python:3.7.16-material-api
cache:
<<: *cache
script:
- mkdir dist
- PYTHONUSERBASE=$CI_PROJECT_DIR/home pip install --upgrade pip -i http://192.168.137.1:8082/repository/pypi-group/simple --trusted-host 192.168.137.1 --user
- PYTHONUSERBASE=$CI_PROJECT_DIR/home pip install -r ./requirements.txt -i http://192.168.137.1:8082/repository/pypi-group/simple --trusted-host 192.168.137.1 --user
- rsync -ha ./ ./dist --exclude=dist --exclude=.git --delete
artifacts:
paths:
- ./dist
expire_in: 7 days
only:
- master
# - test
# - production
deploy:master:
<<: *import_ssh_key
image: instrumentisto/rsync-ssh
stage: deploy
variables:
GIT_STRATEGY: none
script:
- rsync -r ./dist/ ${DEPLOY_DEV_HOST_IP}:${DEPLOY_PATH} --delete
- ssh ${SSH_OPTS} ${DEPLOY_DEV_HOST_IP} "cd ${DEPLOY_PATH} && source /etc/profile && docker-compose up -d --force-recreate"
only:
- master