Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
adds envconsul to inject secrets into container. allows container to …
Browse files Browse the repository at this point in the history
…be run in "sidekiq" mode
  • Loading branch information
Dann Bohn committed Sep 25, 2019
1 parent 16c6bd7 commit aa5aedf
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | b
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

### Envconsul
RUN curl -Lo /tmp/envconsul.zip https://releases.hashicorp.com/envconsul/0.9.0/envconsul_0.9.0_linux_amd64.zip && \
unzip /tmp/envconsul.zip -d /bin && \
rm /tmp/envconsul.zip

RUN . $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
Expand All @@ -35,6 +40,6 @@ RUN bundle install

COPY . /app

RUN aws_bucket=bucket aws_access_key_id=key aws_secret_access_key=access aws_region=us-east-1 rails assets:precompile
RUN RAILS_ENV=production SECRET_KEY_BASE=$(bundle exec rails secret) aws_bucket=bucket aws_access_key_id=key aws_secret_access_key=access aws_region=us-east-1 rails assets:precompile

CMD ["./entrypoint.sh"]
1 change: 0 additions & 1 deletion app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@

/* uppy styles from https://transloadit.edgly.net/releases/uppy/v1.4.0/uppy.min.css placed in ./uppy/uppy.css
*/
require 'uppy'
3 changes: 2 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.js_compressor = :uglifier
config.assets.js_compressor = Uglifier.new(harmony: true)
# config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
Expand Down
28 changes: 25 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
#!/bin/bash
set -e

rails db:create
rails db:migrate
# Vault init container will drop the token in /etc/vault/token; alternatively we can set the VAULT_TOKEN env variable
if [ -f /vault/token ]; then
export VAULT_TOKEN=$(cat /vault/token)
fi

rails s -b '0.0.0.0'
function start_envconsul() {
set -u
envconsul \
-vault-addr=${VAULT_ADDR} \
-secret=${VAULT_PATH} \
-vault-token=${VAULT_TOKEN} \
-no-prefix=true \
-vault-renew-token=false \
-once \
-exec='bash start.sh'
}


if [ -n "${VAULT_TOKEN}" ]; then
echo "have token. starting envconsul"
start_envconsul
else
echo "starting the app"
bash start.sh
fi
11 changes: 11 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


if [ ${APP_ROLE:-app} == "sidekiq" ]; then
echo "starting sidekiq"
bundle exec sidekiq
else
echo "starting rails"
rails db:create
rails db:migrate
rails s -b '0.0.0.0'
fi

0 comments on commit aa5aedf

Please sign in to comment.