Updated Docker setup.
* Use ruby version 3 * Use bundle container * Run rails commands as app user
This commit is contained in:
parent
6d338ffa9e
commit
0bdeaa1570
3 changed files with 37 additions and 33 deletions
37
Dockerfile
37
Dockerfile
|
@ -1,39 +1,38 @@
|
||||||
FROM ruby:2.1-slim
|
# Based on ruby image, packed with a lot of development dependencies
|
||||||
|
FROM ruby:2.3
|
||||||
|
|
||||||
|
# Install all dependencies for development and testing
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install --no-install-recommends -y \
|
apt-get install --no-install-recommends -y \
|
||||||
mysql-client \
|
mysql-client \
|
||||||
git \
|
|
||||||
make \
|
|
||||||
gcc \
|
|
||||||
g++ \
|
|
||||||
patch \
|
|
||||||
libsqlite3-dev \
|
|
||||||
libv8-dev \
|
libv8-dev \
|
||||||
libmysqlclient-dev \
|
libmysqlclient-dev \
|
||||||
libxml2-dev \
|
|
||||||
libxslt1-dev \
|
|
||||||
libffi-dev \
|
|
||||||
libreadline-dev \
|
|
||||||
xvfb \
|
xvfb \
|
||||||
iceweasel && \
|
iceweasel && \
|
||||||
rm -rf /var/lib/apt/lists/* && \
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
apt-get clean
|
apt-get clean
|
||||||
|
|
||||||
ENV WORKDIR /usr/src/app
|
# Run app and all commands as user 'app'. This avoids changing permissions
|
||||||
|
# for files in mounted volume.
|
||||||
|
RUN adduser --gecos GECOS --disabled-password --shell /bin/bash app
|
||||||
|
USER app
|
||||||
|
|
||||||
RUN mkdir -p $WORKDIR
|
# Create an directory to store the application code.
|
||||||
WORKDIR $WORKDIR
|
RUN mkdir /home/app/src
|
||||||
|
WORKDIR /home/app/src
|
||||||
|
|
||||||
# Copy plugins before the rest to allow bundler loading gemspecs
|
# Copy plugins before the rest to allow bundler loading gemspecs
|
||||||
# TODO: Move plugins to gems and add them to Gemfile instead
|
# TODO: Move plugins to gems and add them to Gemfile instead
|
||||||
COPY plugins $WORKDIR/plugins
|
COPY plugins ./plugins
|
||||||
|
|
||||||
COPY Gemfile $WORKDIR/
|
# Add Gemfiles and run bundle.
|
||||||
COPY Gemfile.lock $WORKDIR/
|
COPY Gemfile Gemfile.lock ./
|
||||||
RUN bundle install --jobs 4
|
ENV BUNDLE_JOBS=4 BUNDLE_PATH=/home/app/bundle \
|
||||||
|
BUNDLE_APP_CONFIG=/home/app/bundle/config
|
||||||
|
RUN bundle install
|
||||||
|
|
||||||
COPY . $WORKDIR
|
# Copy the application code. (Excluded files see .dockerignore)
|
||||||
|
COPY . ./
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@ This document explains setting up and using Foodsoft with Docker.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
* Docker (=> 1.5)
|
* Docker (=> 1.9.1)
|
||||||
* Docker Compose (=> 1.1)
|
* Docker Compose (=> 1.4)
|
||||||
* Nothing more, no ruby, mysql, redis etc!
|
* Nothing more, no ruby, mysql, redis etc!
|
||||||
|
|
||||||
For installing instructions see https://docs.docker.com/installation/.
|
For installing instructions see https://docs.docker.com/installation/.
|
||||||
|
@ -49,19 +49,16 @@ Jump in a running container for debugging.
|
||||||
|
|
||||||
docker exec -ti foodsoft_app_1 bash
|
docker exec -ti foodsoft_app_1 bash
|
||||||
|
|
||||||
|
Receiving mails
|
||||||
|
|
||||||
|
Go to http://localhost:1080.
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
### Gemfile updates
|
### Gemfile updates
|
||||||
|
|
||||||
This is bit tricky, as the gemfiles are stored in the container and so we have
|
As we use a special container (`bundle`, see `docker-compose.yml`) you only
|
||||||
to rebuild the container each time we change the Gemfile. To avoid installing
|
have to run the bundle command as normally: `docker-compose run app bundle`
|
||||||
all the gems from scratch we can use this workaround:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
docker-compose run app bundle update rails # Update Gemfile.lock file
|
|
||||||
docker ps -a # Look for the last exited container and grab the Container ID
|
|
||||||
docker commit -m "Updated rails" <Container ID> foodsoft_app
|
|
||||||
```
|
|
||||||
|
|
||||||
### Database configuration
|
### Database configuration
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
|
bundle:
|
||||||
|
image: foodsoft_app
|
||||||
|
command: /bin/true
|
||||||
|
volumes:
|
||||||
|
- /home/app/bundle
|
||||||
|
|
||||||
app: &app
|
app: &app
|
||||||
build: .
|
build: .
|
||||||
command: bundle exec rails server --binding 0.0.0.0
|
command: bundle exec rails server --binding 0.0.0.0
|
||||||
|
volumes_from:
|
||||||
|
- bundle
|
||||||
volumes:
|
volumes:
|
||||||
- .:/usr/src/app
|
- .:/home/app/src
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
links:
|
links:
|
||||||
|
@ -10,10 +18,10 @@ app: &app
|
||||||
- redis
|
- redis
|
||||||
- mailcatcher
|
- mailcatcher
|
||||||
environment:
|
environment:
|
||||||
- DATABASE_URL=mysql2://root:secret@mysql/development
|
- DATABASE_URL=mysql2://root:secret@mysql/development?encoding=utf8
|
||||||
- REDIS_URL=redis://redis:6379
|
- REDIS_URL=redis://redis:6379
|
||||||
- QUEUE=foodsoft_notifier
|
- QUEUE=foodsoft_notifier
|
||||||
- TEST_DATABASE_URL=mysql2://root:secret@mysql/test
|
- TEST_DATABASE_URL=mysql2://root:secret@mysql/test?encoding=utf8
|
||||||
|
|
||||||
resque:
|
resque:
|
||||||
<<: *app
|
<<: *app
|
||||||
|
|
Loading…
Reference in a new issue