-
Notifications
You must be signed in to change notification settings - Fork 324
Use Docker to run Smashing
Docker became an convenient way to deploy applications - even more with interpreted languages such as Ruby. Because Smashing uses the Ruby runtime and dependencies that aren't directly saved on systems by default, it appears to be a good idea to containerize the whole application to avoid potential libraries conflicts and breaking system updates.
Only a simple installation of Docker is required here.
- Docker and docker-compose (find your suitable versions on docker.com).
You can clone the following Github repository which contains examples of required files : https://github.com/atilleh/docker-smashing. The idea here is to create or use 5 different files that are fundamentals dependencies for Docker to create a well-running Smashing application.
-
docker-compose.yml
: orchestrates the container deployment, volume mount operations and port exposure. -
Dockerfile
: recipe of 'how to build the image' -
entrypoint.sh
: firstly executed on image, make us able to use Smashing CLI directly on container. -
Gemfile
: default Smashing dependencies. -
.env
: Twitter module's secrets and self-defined Smashing API key.
Without taking care of environment variables or networks binding, here's the minimal required docker-compose.yml
:
version: '3'
services:
smashing:
hostname: smashing
command: bash -c "rm -f tmp/pids/server.pid && bundle exec smashing start -p 3030 -a '0.0.0.0'"
build:
dockerfile: Dockerfile
context: .
ports:
- 3030:3030
volumes:
- ./smashing:/smashing
To build the image, we need to install required dependencies (such as Nodejs) and install Ruby libraries (Smashing, Twitter) :
FROM ruby:2.6
RUN mkdir /smashing
RUN apt-get update && \
apt-get upgrade -yq && \
apt-get install -yq nodejs
COPY Gemfile /smashing/Gemfile
WORKDIR /smashing
RUN bundle install --jobs 80
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3030
CMD ["smashing", "start", "-p", "3030"]
This file is extremely important but only contains three lines. The second one "copies" the docker-compose run...
command to the container. We'll then be able to use Smashing CLI inside our container.
#!/bin/bash
set -e
exec "$@"
To install cross-requirement libraries on our image, we need to already declare we'd like to use Smashing and the Twitter gem.
# frozen_string_literal: true
source 'https://rubygems.org'
gem 'smashing'
gem 'twitter', '>= 5.9.0'
This file is automatically loaded by docker-compose
and must contain secrets: we store Twitter credentials here to do not share them on smashing/jobs/twitter.rb
file. You need to fill them.
SMASHING_KEY=
TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=
TWITTER_ACCESS_TOKEN=
TWITTER_TOKEN_SECRET=
With all these 5 files on our directory, we can now build the image and create a classic Smashing installation:
# first smashing is container name
# second smashing is CLI name inside of container.
docker-compose run smashing smashing new .
docker-compose up -d
docker ps # container should be binded to :3030
- Home
- Dashing Workshop
- Installation
- Widgets
- Configuration
- Security
- Troubleshooting
- Deploying dashboards
- How Tos
- How to: post data to your dashboard and widgets
- How to: Define a data model and store history data to database
- How to: Prevent a job from overlapping with itself
- How to: Send HTML data to your widgets
- How to: Send mysql data to your widgets
- How to: Setup a Graph
- How to: Store data to and display from database
- How to: Update a Dashboard using a spreadsheet
- How to: update dashboard in Django
- How to: Update font awesome fonts from version 3 to 4
- How to: Use New Relic with Dashing
- How to: precompile assets
- Development