Skip to content

Instantly share code, notes, and snippets.

@htuscher
Created November 17, 2017 12:46
Show Gist options
  • Save htuscher/48d21e2c95fe5ab0a1d73dc071004a45 to your computer and use it in GitHub Desktop.
Save htuscher/48d21e2c95fe5ab0a1d73dc071004a45 to your computer and use it in GitHub Desktop.
Gitlab-CI simple deployment
exclude .cache
exclude .editorconfig
exclude .git
exclude .gitattributes
exclude .github
exclude .gitignore
exclude .travis.yml
exclude /Build
exclude /Tests
exclude /*.md
protect /.*
protect /*.txt
protect /*.htm
protect /*.html
protect /Configuration/**
protect /Data/**
protect /Web/**
stages:
- deploy
variables:
#--------------------------------------------------------#
# PROJECT SPECIFIC VARIABLES #
#--------------------------------------------------------#
COMPOSE_PROJECT_NAME: heavenstaste_$CI_PIPELINE_ID
#--------------------------------------------------------#
# GENERAL VARIABLES #
#--------------------------------------------------------#
SITE_PACKAGE: Jhoechtl.Heavenstaste
BASE_PATH: ${CI_PROJECT_DIR}/app/Repository/${SITE_PACKAGE}/
TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_PIPELINE_ID
RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
STAGE_IMAGE: $CI_REGISTRY_IMAGE:stage
DEV_IMAGE: $CI_REGISTRY_IMAGE:develop
CACHE_DIR: .cache
COMPOSER_CACHE_DIR: ${CI_PROJECT_DIR}/${CACHE_DIR}/composer
bower_storage__packages: ${CI_PROJECT_DIR}/${CACHE_DIR}/bower
YARN_CACHE_FOLDER: ${CI_PROJECT_DIR}/${CACHE_DIR}/yarn
RSYNC: rsync -rtqx --links --safe-links --chmod=Du=rwx,Dgo=rx,Fu=rw,Fog=r --delete
#--------------------------------------------------------#
# DEPLOYMENT VARIABLES (no Docker) #
#--------------------------------------------------------#
DEV_DOMAIN: https://heavenstaste.it-jh.de
DEV_USER: heavenstaste
DEV_SERVER: it-jh.de
DEV_PATH: /var/www/clients/client0/web54/private
DEV_PHP_PATH: /opt/php-7.0.16/bin/php
DEV_PORT: '22'
LIVE_DOMAIN: https://www.heavenstaste.de
LIVE_USER: ssd1297
LIVE_SERVER: ssd3.ssdhosting.a1a-server.de
LIVE_PATH: /var/www/ssd1297/htdocs
LIVE_PHP_PATH: /usr/bin/php
LIVE_PORT: '22'
cache:
key: global
paths:
- $CACHE_DIR
#####################################
# DEPLOYMENTS #
#####################################
deploy_dev:
image: 1drop/php-70-docker-utils
stage: deploy
environment:
name: development
url: $DEV_DOMAIN
before_script:
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- composer install --no-dev --no-progress --no-interaction -d app
script:
- git lfs install && git lfs pull
- cd app
- $RSYNC -e "ssh -p $DEV_PORT" --filter="merge ../.deploy-filter" . $DEV_USER@$DEV_SERVER:$DEV_PATH
- ssh $DEV_USER@$DEV_SERVER DEPLOY_DIR=$DEV_PATH PHP_BIN=$DEV_PHP_PATH 'bash -s' < ../deploy.sh
when: manual
only:
- develop
deploy_live:
image: 1drop/php-70-docker-utils
stage: deploy
environment:
name: production
url: $LIVE_DOMAIN
before_script:
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- composer install --no-dev --no-progress --no-interaction -d app
script:
- cd app
- $RSYNC -e "ssh -p $LIVE_PORT" --filter="merge ../.deploy-filter" . $LIVE_USER@$LIVE_SERVER:$LIVE_PATH
- ssh $LIVE_USER@$LIVE_SERVER DEPLOY_DIR=$LIVE_PATH PHP_BIN=$LIVE_PHP_PATH 'bash -s' < ../deploy.sh
when: manual
only:
- master
#!/bin/bash
export FLOW_CONTEXT=Production
cd $DEPLOY_DIR
mv Web/index.php Web/index.php2
sleep 5
# Ensure Production environment
sed -i 's/Development/Production/' Web/index.php2
# Fix path to PHP CLI when using ./flow
sed -i "s#/usr/bin/env php#$PHP_BIN#" flow flow
composer install --no-dev --no-progress --no-interaction
rm Configuration/PackageStates.php
$PHP_BIN flow flow:cache:flush --force
$PHP_BIN flow doctrine:migrate
$PHP_BIN flow resource:publish
mv Web/index.php2 Web/index.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment