Opinionated Docker image based on Alpine Linux 3.6 that contains the bare minimum to run a GraphQL API server.
Note: You must have Packer installed if you want to rebuild the Docker image!
- supervisor (3.2.4-r0)
- nginx (1.12.2-r0)
- ruby (2.4.2-r0)
- ruby-rake (2.4.2-r0)
- ruby-bigdecimal (2.4.2-r0)
- ruby-bundler (1.15.4-r0)
- ruby-json (2.4.2-r0)
At the top of the packer.yml
file you will see the version numbers specified like so:
variables:
rails_version: '5.1.4'
nokogiri_version: '1.8.1'
cityhash_version: '0.9.0'
bcrypt_version: '3.1.11'
graphql_version: '1.1.0'
oj_version: '3.3.9'
pg_version: '0.21'
Just fill out the verson numbers that you want installed, and run ./build.rb
to rebuild the image. Almost works like magic!
- Add this to the top of your
Dockerfile
:
FROM nater540/alpine-rails-api:latest
-
Copy your application code into
/home/app/project_name_goes_here
-
End your
Dockerfile
with this:
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisor.conf"]
This container does NOT include a Ruby server because everyone has their own preference; having said that, I generally perfer to use Puma as my server of choice.
Here is the supervisor config that I use for Puma:
[program:puma]
directory=/home/app/project_name_goes_here
command=/usr/bin/puma -C config/puma.rb
process_name=%(program_name)s
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stopasgroup=false
killasgroup=false
autorestart=true
autostart=true
startretries=3
startsecs=10
stopsignal=TERM
stopwaitsecs=10
exitcodes=0,2
username=app
priority=999
numprocs=1
umask=022
This file should be copied into /etc/supervisor/conf.d
to work properly.
Nginx is included and set to startup when the container is brought up.
The default site file is located at /etc/nginx/conf.d/default.conf
and is configured to return a 404 Not Found
error.
Heads Up
It is strongly recommended that you read this guide first so that you are familiar with creating base images.
Without further ado, here is how you rebuild the base image and publish it!
- Install any required gems:
bundle install
- Run the following command:
./build.rb