Last active
August 14, 2018 08:32
-
-
Save placek/3dd2bd9b5157349d7d5c46f45b4db60d to your computer and use it in GitHub Desktop.
CI/CD with bash/git/docker-compose
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
default: &default | |
adapter: postgresql | |
encoding: unicode | |
host: db | |
username: postgres | |
password: | |
pool: 5 | |
development: | |
<<: *default | |
database: landing_politechnika_development | |
test: | |
<<: *default | |
database: landing_politechnika_test |
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
FROM ruby:2.5.1-alpine3.7 | |
RUN apk add --no-cache --update build-base linux-headers git postgresql-dev nodejs tzdata | |
ENV APP_PATH /www | |
RUN mkdir -p $APP_PATH | |
WORKDIR $APP_PATH | |
COPY Gemfile $APP_PATH/Gemfile | |
COPY Gemfile.lock $APP_PATH/Gemfile.lock | |
RUN echo "gem: --no-rdoc --no-ri" >> ".gemrc" | |
RUN bundle install --jobs 20 --retry 5 | |
COPY . $APP_PATH |
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
version: '3' | |
services: | |
db: | |
image: postgres:alpine | |
restart: always | |
volumes: | |
- ../db:/var/lib/postgresql/data | |
web: | |
build: | |
context: . | |
dockerfile: Dockerfile.local.ci | |
container_name: landing_politechnika | |
env_file: .env | |
command: | |
bundle exec unicorn --config-file config/unicorn.rb --env $RAILS_ENV | |
volumes: | |
- .:/var/opt/www | |
ports: | |
- "3000:8080" | |
depends_on: | |
- db |
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
#!/usr/bin/env bash | |
refname=$1 | |
if [[ $refname == "refs/tags/deploy" ]] | |
then | |
if [[ -f $refname ]] | |
then | |
echo "[DEPLOY] $rev" | |
git tag --verify deploy | |
rev=$(cat $refname) | |
mkdir $rev | |
git archive $rev | tar -xf - -C $rev | |
[ -d shared ] && cp -R shared/. $rev | |
pushd $rev | |
docker-compose --file local.ci.yml up --detach | |
popd | |
ln -s $rev current | |
else | |
echo "[ HALT ] $(readlink current)" | |
pushd current | |
docker-compose --file local.ci.yml down | |
popd | |
rm -rf $(readlink current) | |
rm -rf current | |
fi | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment