Last active
November 5, 2018 22:09
-
-
Save zinovyev/e441f63921908f48ca66f19faf4496d2 to your computer and use it in GitHub Desktop.
A Makefile to deploy docker wrapped ROR app to a VPS
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
RAILS_ENV := "development" | |
PUBLISHED_PORT := "8080" | |
DOCKER_CMD := "bundle exec rails s -b 0.0.0.0 -p 3000" | |
PROJECT := $(shell basename ${PWD}) | |
COMMAND_ENV := "RAILS_ENV=${RAILS_ENV}" | |
TIMESTAMP := $(shell /bin/date +%Y%m%d%H%M%S) | |
#IMAGE_NAME := "${PROJECT}:${TIMESTAMP}" | |
IMAGE_NAME := "${PROJECT}:latest" | |
APP_PATH := "/opt/apps/${PROJECT}" | |
all: clear_images build_image bundle_install db_migrate clear_containers start_rails | |
clear_images: | |
/bin/bash -c "docker images | grep ${PROJECT} | \ | |
awk '{ print \"docker rmi -f \"\$$3 }' | bash ; true" | |
build_image: | |
docker build -t ${IMAGE_NAME} . | |
bundle_install: | |
docker run --rm -e "${COMMAND_ENV}" -e "WORKDIR=${APP_PATH}" \ | |
-v "${PWD}:${APP_PATH}" -v "${PROJECT}-bundle:/usr/local/bundle" \ | |
${IMAGE_NAME} bundle install | |
db_migrate: | |
docker run --rm -e "${COMMAND_ENV}" -e "WORKDIR=${APP_PATH}" \ | |
-v "${PWD}:${APP_PATH}" -v "${PROJECT}-bundle:/usr/local/bundle" \ | |
${IMAGE_NAME} bundle exec rake db:migrate | |
clear_containers: | |
/bin/bash -c "docker ps | grep ${PROJECT} | awk '{ print \"docker kill \"\$$1 }' | bash" | |
docker run --rm -v "${PWD}:${APP_PATH}" ${IMAGE_NAME} \ | |
rm "${APP_PATH}/tmp/pids/server.pid" ; true | |
start_rails: | |
touch "${PWD}/log/docker.log" | |
nohup docker run --rm -e "${COMMAND_ENV}" -v "${PWD}:${APP_PATH}" \ | |
-v "${PROJECT}-bundle:/usr/local/bundle" -p ${PUBLISHED_PORT}:3000 \ | |
${IMAGE_NAME} "${DOCKER_CMD}" &>"${PWD}/log/docker.log" & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment