Last active
January 31, 2024 18:30
-
-
Save assimovt/0084b9ad01a26de93f29e1fe9ba90de4 to your computer and use it in GitHub Desktop.
Dockbit Dev environment
This file contains hidden or 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
#!/bin/bash | |
# | |
# Dockbit Dev Box setup script. | |
# | |
set -e | |
VERBOSE=0 | |
DRY=0 | |
function print_help() { | |
echo "Sets up Dockbit Dev Box with all the nuts and bolts." | |
echo | |
echo "Usage:" | |
echo " $0 [-h] [-v] [-s]" | |
echo | |
echo "Options:" | |
echo -e " -h \t For usage help." | |
echo -e " -v \t Verbose mode - show output of all commands." | |
echo -e " -d \t Dry run mode - show only what will do." | |
echo | |
} | |
function print_hi() { | |
echo | |
echo -e "\033[94m π€ Setting up Dockbit Dev Box. Keep tight... \033[0m" | |
echo | |
} | |
function print_bye() { | |
echo | |
echo -e "\033[97m All done! Go and build something awesome now π π\033[0m" | |
echo | |
echo -e " Your dev box is running at \033[97mhttp://docker:3000\033[0m" | |
echo -e " For more help \033[97mdocker-compose -h\033[0m" | |
echo | |
} | |
function run_step() { | |
printf " \033[97m%-24s\033[0m" "$1" | |
shift | |
[ $VERBOSE -eq 0 ] && out="> /dev/null 2>&1" | |
[ $DRY -eq 1 ] && dry="echo" | |
eval "$dry $@ $out" | |
if [ $VERBOSE -eq 0 ] ; then | |
echo -e "\033[97m β\033[0m" | |
fi | |
} | |
while getopts ":vdh" opt; do | |
case $opt in | |
v) | |
VERBOSE=1 | |
;; | |
d) | |
DRY=1 | |
;; | |
h) | |
print_help | |
exit 0 | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
exit 1 | |
;; | |
:) | |
echo "Option -$OPTARG requires an argument." >&2 | |
exit 1 | |
;; | |
esac | |
done | |
print_hi | |
# Substitute user variable data | |
cat docker-compose.example.yml | sed "s#{{HOME}}#$HOME#g" > docker-compose.yml | |
run_step "Building image" \ | |
docker-compose build | |
run_step "Bringing up app" \ | |
docker-compose up -d | |
run_step "Setting up database" \ | |
docker-compose run web rails db:create db:schema:load | |
print_bye |
This file contains hidden or 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: '2' | |
services: | |
web: &app_base | |
build: . | |
command: rails server -p 3000 -b 0.0.0.0 | |
depends_on: | |
- postgres | |
- redis | |
- vault | |
ports: | |
- 3000:3000 | |
links: | |
- postgres | |
- redis | |
volumes: | |
- .:/app | |
- {{HOME}}/.docker/machine/certs:/etc/ssl/docker | |
volumes_from: | |
- bundle | |
environment: | |
VAULT_ADDR: http://192.168.99.100:8200 | |
VAULT_TOKEN: 8d2b46d1-a2b6-3728-4da1-12a52e40df7f | |
bundle: | |
image: app_web | |
command: echo Data container for Bundler... | |
volumes: | |
- /bundle | |
postgres_data: | |
image: app_web | |
command: echo Data container for Postgres... | |
volumes: | |
- /var/lib/postgresql/data | |
postgres: | |
image: postgres:9.4 | |
volumes_from: | |
- postgres_data | |
redis: | |
image: redis:3.0 | |
sidekiq: | |
<<: *app_base | |
ports: [] | |
command: sidekiq -C ./config/sidekiq.yml | |
vault: | |
image: cgswong/vault:0.5.2 | |
command: server -dev | |
ports: | |
- 8200:8200 | |
environment: | |
VAULT_DEV_LISTEN_ADDRESS: 0.0.0.0:8200 | |
VAULT_DEV_ROOT_TOKEN_ID: 8d2b46d1-a2b6-3728-4da1-12a52e40df7f |
This file contains hidden or 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.3 | |
MAINTAINER [email protected] | |
# Install app dependencies | |
RUN apt-get update -qq && apt-get install -y \ | |
build-essential \ | |
libpq-dev \ | |
unzip \ | |
telnet \ | |
vim \ | |
nodejs | |
# Install Hashicorp Vault | |
ENV VAULT_VERSION 0.5.2 | |
RUN curl -SL https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip > /tmp/vault.zip && \ | |
cd /bin && unzip /tmp/vault.zip && chmod +x /bin/vault && rm /tmp/vault.zip | |
# Create working directory | |
ENV APP_HOME /app | |
RUN mkdir -p $APP_HOME | |
WORKDIR $APP_HOME | |
# Set up Bundler and application tree | |
ENV BUNDLE_GEMFILE=$APP_HOME/Gemfile \ | |
BUNDLE_JOBS=2 \ | |
BUNDLE_PATH=/bundle | |
COPY Gemfile* $APP_HOME/ | |
RUN bundle install | |
COPY . $APP_HOME | |
EXPOSE 3000 |
This file contains hidden or 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
#!/bin/bash | |
# Just a tiny wrapper around `docker-compose` | |
docker-compose run web $* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment