Created
June 4, 2019 07:32
-
-
Save EvilWolf/7642588e5cf65393cd9d02d7c5add0e9 to your computer and use it in GitHub Desktop.
Grav cms - deploy by gitlab.ci
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stages: | |
- build | |
- deploy | |
variables: | |
RELEASE_ARCHIVE: "release_${CI_COMMIT_SHORT_SHA}.tar.gz" | |
make archive: | |
stage: build | |
image: alpine:latest | |
script: | |
- rm -rf *.md composer.* .gitlab-ci.yml LICENSE.txt .git bin webserver-configs | |
- tar -cpzf $RELEASE_ARCHIVE .??* * --exclude=./$RELEASE_ARCHIVE | |
artifacts: | |
paths: | |
- "$RELEASE_ARCHIVE" | |
expire_in: 1 day | |
only: | |
- master | |
deploy to beget: | |
stage: deploy | |
image: alpine:latest | |
variables: | |
PROD_DEPLOY_PATH: "${SSH_PRODUCTION_ROOT}/release_${CI_COMMIT_SHORT_SHA}" | |
PROD_PUBLIC: "${SSH_PRODUCTION_ROOT}/public_html" | |
PROD_ARCHIVE: "${SSH_PRODUCTION_ROOT}/release_${CI_COMMIT_SHORT_SHA}.tar.gz" | |
before_script: | |
- apk update && apk add openssh-client bash && mkdir -p ~/.ssh | |
- eval $(ssh-agent -s) | |
- echo "$SSH_PRIVATE_KEY" | ssh-add - | |
- ssh-keyscan -H $SSH_HOST >> ~/.ssh/known_hosts | |
script: | |
- scp $RELEASE_ARCHIVE "$SSH_USER@$SSH_HOST:$SSH_PRODUCTION_ROOT" | |
- ssh "$SSH_USER@$SSH_HOST" "mkdir -p $PROD_DEPLOY_PATH && tar -zxf $PROD_ARCHIVE -C $PROD_DEPLOY_PATH" | |
- ssh "$SSH_USER@$SSH_HOST" "cd $PROD_PUBLIC && find . -delete && shopt -s dotglob && mv $PROD_DEPLOY_PATH/* $PROD_PUBLIC" | |
- ssh "$SSH_USER@$SSH_HOST" "rm -rf $PROD_ARCHIVE && rm -rf $PROD_DEPLOY_PATH && shopt -u dotglob" | |
only: | |
- master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment