diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 739665dc..b760a1d7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,6 +7,18 @@ build: script: - docker build --build-arg=COMMIT=$(git rev-parse --short HEAD) . -t "cmc:latest" +deploy_staging: + stage: deploy + script: + - cd /home/cmc/staging/ + - git pull origin master + - echo "Run the new docker image" + - /home/cmc/cmc-sales/run_docker_stg.sh + environment: + name: staging + only: + - master + deploy_production: stage: deploy script: @@ -17,6 +29,6 @@ deploy_production: - /home/cmc/cmc-sales/run_docker.sh environment: name: production - + when: manual only: - master diff --git a/Dockerfile_stg b/Dockerfile_stg new file mode 100644 index 00000000..c06b1c45 --- /dev/null +++ b/Dockerfile_stg @@ -0,0 +1,63 @@ +# This is 99% the same as the prod one. I should do something smarter here. + +FROM ubuntu:lucid + +# Set environment variables. +ENV HOME /root + +# Define working directory. +WORKDIR /root + +RUN sed -i 's/archive/old-releases/' /etc/apt/sources.list + + +RUN apt-get update +RUN apt-get -y upgrade + +# Install apache, PHP, and supplimentary programs. curl and lynx-cur are for debugging the container. +RUN DEBIAN_FRONTEND=noninteractive apt-get -y install apache2 libapache2-mod-php5 php5-mysql php5-gd php-pear php-apc php5-curl php5-imap + +# Enable apache mods. +#RUN php5enmod openssl +RUN a2enmod php5 +RUN a2enmod rewrite +RUN a2enmod headers + + +# Update the PHP.ini file, enable tags and quieten logging. +# RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php5/apache2/php.ini +#RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" /etc/php5/apache2/php.ini + +ADD conf/php.ini /etc/php5/apache2/php.ini + +# Manually set up the apache environment variables +ENV APACHE_RUN_USER www-data +ENV APACHE_RUN_GROUP www-data +ENV APACHE_LOG_DIR /var/log/apache2 +ENV APACHE_LOCK_DIR /var/lock/apache2 +ENV APACHE_PID_FILE /var/run/apache2.pid + +ARG COMMIT +ENV COMMIT_SHA=${COMMIT} + +EXPOSE 80 + +# Update the default apache site with the config we created. +ADD conf/apache-vhost.conf /etc/apache2/sites-available/cmc-sales +ADD conf/ripmime /bin/ripmime + +RUN chmod +x /bin/ripmime +RUN a2dissite 000-default + +# Copy site into place. +ADD . /var/www/cmc-sales +ADD app/config/database_stg.php /var/www/cmc-sales/app/config/database.php +RUN mkdir /var/www/cmc-sales/app/tmp +RUN mkdir /var/www/cmc-sales/app/tmp/logs +RUN chmod -R 755 /var/www/cmc-sales/app/tmp +RUN chmod +x /var/www/cmc-sales/run_vault.sh + +RUN a2ensite cmc-sales + +# By default, simply start apache. +CMD /usr/sbin/apache2ctl -D FOREGROUND diff --git a/app/config/database_stg.php b/app/config/database_stg.php new file mode 100644 index 00000000..732e4746 --- /dev/null +++ b/app/config/database_stg.php @@ -0,0 +1,52 @@ + 'mysql', + 'persistent' => false, + 'host' => '172.17.0.1', + 'login' => 'cmc', + 'password' => 'cmc', + 'database' => 'cmc', + 'prefix' => '', + ); + } + +} else { + + + class DATABASE_CONFIG { + + var $default = array( + 'driver' => 'mysql', + 'persistent' => false, + 'host' => '172.17.0.1', + 'login' => 'staging', + 'password' => 'stagingmoopwoopVerySecure', + 'database' => 'staging', + 'prefix' => '', + ); + + +// there are no tests... + var $test = array( + 'driver' => 'mysql', + 'persistent' => false, + 'host' => 'localhost', + 'login' => 'user', + 'password' => 'password', + 'database' => 'test_database_name', + 'prefix' => '', + ); + } + + +} diff --git a/backup.sh b/backup.sh index 0775e621..e9a83b9b 100644 --- a/backup.sh +++ b/backup.sh @@ -2,3 +2,4 @@ FILENAME=backups/backup_$(date +'%Y%m%d-%H%M%S').sql.gz mysqldump cmc | gzip > $FILENAME rclone copy $FILENAME gdrivebackups:database/ +rclone sync cmc-sales/app/webroot/pdf gdrivebackups:pdf/ diff --git a/build_docker_stg.sh b/build_docker_stg.sh new file mode 100644 index 00000000..7700e674 --- /dev/null +++ b/build_docker_stg.sh @@ -0,0 +1,3 @@ +ID=$(docker ps -f ancestor=cmc:staging -q) +docker kill $ID +docker build -f Dockerfile_stg . -t "cmc:stg" diff --git a/run_docker_local.sh b/run_docker_local.sh index 0f26f0c8..86a1ff4a 100755 --- a/run_docker_local.sh +++ b/run_docker_local.sh @@ -4,4 +4,4 @@ sleep 1 docker run -d -p 127.0.0.1:8888:80 \ --mount type=bind,source=/home/k/projects/cmc-sales/app/webroot/pdf,target=/var/www/cmc-sales/app/webroot/pdf \ --mount type=bind,source=/home/k/projects/cmc-sales/app/webroot/attachments_files,target=/var/www/cmc-sales/app/webroot/attachments_files \ - cmc:latest + cmc:stg diff --git a/run_docker.sh b/run_docker_prd.sh similarity index 100% rename from run_docker.sh rename to run_docker_prd.sh diff --git a/run_docker_stg.sh b/run_docker_stg.sh new file mode 100755 index 00000000..f7f5a4c3 --- /dev/null +++ b/run_docker_stg.sh @@ -0,0 +1,9 @@ +ID=$(docker ps -q) +docker kill $ID +sleep 1 +docker run -d -p 127.0.0.1:9999:80 \ + --mount type=bind,source=/home/cmc/staging/app/webroot/pdf,target=/var/www/cmc-sales/app/webroot/pdf \ + --mount type=bind,source=/home/cmc/staging/app/webroot/attachments_files,target=/var/www/cmc-sales/app/webroot/attachments_files \ + --mount type=bind,source=/home/cmc/staging/vault/emails,target=/var/www/emails \ + --mount type=bind,source=/home/cmc/staging/vault/vaultmsgs,target=/var/www/vaultmsgs \ + cmc:stg