Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Grav cms - deploy by gitlab.ci
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
You can’t perform that action at this time.