Skip to content

Commit

Permalink
Add Dockerfile (#28)
Browse files Browse the repository at this point in the history
* First Dockerfile
* Fixed dependencies
* Dependency build order sped up
* rm .env
* Update README.md
* Add Windows quirks to ReadMe
* Add rails webpacker:install to the readme
* Gemfile bump

Co-authored-by: tumbleshack <[email protected]>
  • Loading branch information
lincolnanders5 and tumbleshack authored Feb 1, 2021
1 parent ba93adc commit 935ebcf
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules
/tmp
/db/data
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@
/yarn-error.log
yarn-debug.log*
.yarn-integrity

.env
/db/data
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM ruby:2.7.0
RUN apt-get update -qq

RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install -y yarn

WORKDIR /cc_server

COPY Gemfile /cc_server/Gemfile
COPY Gemfile.lock /cc_server/Gemfile.lock
RUN bundle install && gem install bundler:2.2.1

COPY package.json /cc_server/package.json
COPY yarn.lock /cc_server/yarn.lock
RUN yarn install --check-files

COPY . /cc_server

# Start the main process.
CMD rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ GEM
nio4r (2.5.4)
nokogiri (1.11.1-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.11.1-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
public_suffix (4.0.6)
puma (5.1.1)
Expand Down Expand Up @@ -212,7 +214,9 @@ GEM
zeitwerk (2.4.2)

PLATFORMS
ruby
x86_64-darwin-19
x86_64-linux

DEPENDENCIES
bootsnap (>= 1.4.4)
Expand Down
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
# Carrie's Closet

## Getting Started
On windows, make sure you set git [to use unix line endings](https://docs.github.com/en/github/using-git/configuring-git-to-handle-line-endings)
when checking out and committing.

If you've already checked out and have windows line endings, you may encounter
an error stating: `env: ruby\r: No such file or directory`. To resolve, run
`find ./ -type f -exec dos2unix {} \;`.

After a clean install of this repo, you'll need to run `bundle install` inside
the `CarriesCloset` root folder. This will install all needed requirements.
the `CarriesCloset` root folder. This will install all needed requirements.

Additionally, **duplicate** the file `example.env` in the root level directory.
Once duplicated, rename the duplicate, e.g. `example.env (1)`, to just `.env`.
This may cause the `.env` to disapear from your file brower, but don't worry
if you've named the file correctly.

## Database Creation
You'll need to have MySQL installed and running locally.
Expand All @@ -25,4 +37,27 @@ bin/rails db:create && bin/rails db:migrate && bin/rails db:seed
create a `Tweet` model that belongs to a `User` model. Each `Tweet` will be
stored in the database with a `body` text field and a `likes` counter.
- `bin/rails destroy Tweet` will revert all generated files for the previous
`Tweet` model.
`Tweet` model.

## Running with Docker
To run the full app stack, run the following commands:
```shell
docker-compose build --parallel && docker-compose up -d
docker exec cc_server sh -c "bin/rails db:create && bin/rails db:migrate && bin/rails db:seed"
docker exec cc_server sh -c "rails webpacker:install"
```

Note that on Windows, you may need to run these command seprately. Eg.
```
docker-compose build --parallel
docker-compose up -d
docker exec cc_server sh -c "bin/rails db:create"
docker exec cc_server sh -c "bin/rails db:migrate"
docker exec cc_server sh -c "bin/rails db:seed"
docker exec cc_server sh -c "rails webpacker:install"
```

This will create the `cc_mysql` MySQL Docker container, the `cc_redis` Redis
caching store, and the `cc_server` Rails server. Both commands should complete
without error to let you know everything is running properly. The Rails server
will run on http://127.0.0.1:3000 in most environments.
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ default: &default
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: root
password:
host: 127.0.0.1
host: <%= ENV['DATABASE_HOST'] %>

development:
<<: *default
Expand Down
49 changes: 49 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: "3.7"
services:
cc_server:
build: .
container_name: cc_server
# restart: unless-stopped
env_file: .env
volumes:
- .:/cc_server:cached
ports:
- 3000:3000
expose:
- 3000
networks:
- container_network
depends_on:
- cc_mysql
- cc_redis
cc_mysql:
container_name: cc_mysql
image: mysql:8.0
command: --default-authentication-plugin=mysql_native_password
# restart: always
env_file: .env
ports:
- "127.0.0.1:3306:3306"
expose:
- 3306
volumes:
- ./db/scripts/:/docker-entrypoint-initdb.d/
- ./db/data/MySQL/:/var/lib/mysql/
networks:
- container_network
cc_redis:
container_name: cc_redis
image: redis:latest
command: redis-server --requirepass $REDIS_PASSWORD --bind cc_redis --port 6379
env_file: .env
ports:
- "127.0.0.1:6379:6379"
expose:
- 6379
volumes:
- ./db/data/Redis:/data
networks:
- container_network
networks:
container_network:
driver: bridge
8 changes: 8 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
RAILS_ENV=development

DATABASE_NAME=CarriesCloset_development
DATABASE_USER=CarriesCloset_development
MYSQL_ALLOW_EMPTY_PASSWORD=true
DATABASE_HOST=cc_mysql

REDIS_PASSWORD=password
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"version": "0.1.0",
"devDependencies": {
"webpack": "^4.43.0",
"webpack-dev-server": "^3.11.2"
}
}
29 changes: 2 additions & 27 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 935ebcf

Please sign in to comment.