Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax = docker/dockerfile:1

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.2.2
ARG RUBY_VERSION=3.0.6
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base

# Rails app lives here
Expand All @@ -19,10 +19,17 @@ FROM base as build

# Install packages needed to build gems and node modules
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential curl git libpq-dev libvips node-gyp pkg-config python-is-python3
apt-get install --no-install-recommends -y \
libpq-dev `# Part of generated dockerfile` \
libvips `# Generated for ActiveRecord` \
node-gyp `# Generated for Node` \
pkg-config `# Generated for Node` \
build-essential \
curl \
libmariadb-dev # Needed by ActiveRecord

# Install JavaScript dependencies
ARG NODE_VERSION=18.18.2
ARG NODE_VERSION=16.13.1
ARG YARN_VERSION=1.22.19
ENV PATH=/usr/local/node/bin:$PATH
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
Expand Down Expand Up @@ -56,13 +63,10 @@ RUN bundle exec bootsnap precompile app/ lib/
# into the container. We will inject RAILS_MASTER_KEY env var when starting the
# container.

# TODO: resolve this in a way that does not require running in development mode.
RUN /bin/bash -c 'if [[ "$RAILS_ENV" == "production" ]]; then \
mv config/credentials.yml.enc config/credentials.yml.enc.backup && \
mv config/credentials/production.yml.enc config/credentials/production.yml.enc.backup && \
mv config/credentials/sample.yml.enc config/credentials.yml.enc && \
mv config/credentials/sample.key config/master.key && \
SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile && \
mv config/credentials.yml.enc.backup config/credentials.yml.enc && \
SECRET_KEY_BASE_DUMMY=1 RAILS_ENV=development ./bin/rails assets:precompile && \
mv config/credentials/production.yml.enc.backup config/credentials/production.yml.enc && \
rm -f config/master.key; \
fi'
Expand All @@ -73,7 +77,12 @@ FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libvips postgresql-client rsync && \
apt-get install --no-install-recommends -y \
libvips `# Generated for ActiveRecord` \
curl \
rsync `# Asset syncing` \
libmariadb-dev `# activerecord` \
nodejs `# js runtime` && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand All @@ -96,4 +105,4 @@ ENTRYPOINT ["/rails/bin/docker-sync-assets-entrypoint"]

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD ["./bin/rails", "server"]
CMD ["./bin/rails", "server", "-b", "0.0.0.0"]
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
source 'https://rubygems.org'

ruby File.read(".ruby-version").strip

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.1.7.1'

Expand Down
55 changes: 38 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,48 @@ You must install and configure a sendmail provider if you wish to send emails fr

## Development Setup

1. Clone the repo and checkout the intended branch.
2. Install MySQL.
3. Install rbenv and initialize it.
4. `rbenv install`
5. `gem install bundler` (ensure this runs in your rbenv environment)
6. `rbenv rehash`
7. `RAILS_ENV=development bundle install`
8. `rbenv rehash`
9. `EDITOR=nano ../rbenv/shims/bundle exec rails credentials:edit`. If you want to test out email or Slack integrations, then copy in the example at [config/credentials/credentials.example.yml](./config/credentials/credentials.example.yml) and update the values for your specific instance.
10. Install Node and Yarn (included in recent versions via corepack).
11. `yarn install`
12. `RAILS_ENV=development rails assets:precompile`
13. Create MySQL databases `abtt_development_master` and `abtt_test`. Use an existing user or create a new user and give it access to these databases. Update `config/database.yml` to match your local install for both the `development` and `test` environments. **Be sure not to commit this file with your specific environmental changes.**
14. `RAILS_ENV=development rails db:schema:load`
15. `RAILS_ENV=development rails db:seed`
16. Run the rails console to create an initial user: `RAILS_ENV=development rails c`
### Initial Setup

1. Install Docker
1. Install MySQL
1. Create MySQL databases `abtt_development_master` and `abtt_test`
1. Create a MySQL user `abtt` with a password of your choice, and
give it access to those databases.

### Making Changes

1. Clone the repo and checkout the intended branch
1. Make changes
1. Build the Docker image: `docker build --tag "tracker" --platform linux/amd64 .`
1. If you are already running tracker, remove it: `docker rm tracker`
1. Run the image:
```
docker run -d \
-e RAILS_ENV=development \
-e DATABASE_URL='mysql2://abtt:mypassword@host.docker.internal/abtt_development_master' \
-p 3000:3000 --platform linux/amd64 --name tracker tracker
```
1. Now you can open tracker at `http://localhost:3000`


If this is your first run, do the following:

1. Load the DB schema: `docker exec tracker ./bin/rails db:schema:load`
1. Load the DB schema: `docker exec tracker ./bin/rails db:seed`
1. Enter Rails console: `docker exec -it tracker ./bin/rails c`
1. Create an initial user:
```ruby
Member.create(namefirst: "Sam", namelast: "Abtek", email: "abtech@andrew.cmu.edu", phone: "5555555555", password: "password", password_confirmation: "password", payrate: 0.0, tracker_dev: true)
exit
```
17. Start the development server: `RAILS_ENV=development puma`

### Configuration

You may use the following environment variables when running the image:

- `RAILS_ENV` - development, staging, production, etc.
- `DATABASE_URL` - e.g. `mysql2://abtt:password@host.docker.internal/abtt_development_master`


## Deployment

Expand Down
Empty file modified bin/docker-entrypoint
100644 → 100755
Empty file.
28 changes: 16 additions & 12 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,32 @@
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html

development:
adapter: mysql2
encoding: utf8mb4
database: abtt_development_master
pool: 5
username: deploy-abtech-tracker
password:
socket: /var/run/mysqld/mysqld.sock
# Use DATABASE_URL environment variable, see example.env file
# database: abtech_tracker_staging-01
# pool: 5
# username: root
# password:
# socket: /var/run/mysqld/mysqld.sock
collation: utf8mb4_bin

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.

test:
adapter: mysql2
encoding: utf8
database: abtt_test
pool: 5
username: deploy-abtech-tracker
password:
socket: /var/run/mysqld/mysqld.sock
collation: utf8_unicode_ci
encoding: utf8mb4
# Use DATABASE_URL environment variable, see example.env file
# database: abtech_tracker_staging-01
# pool: 5
# username: root
# password:
# socket: /var/run/mysqld/mysqld.sock
collation: utf8mb4_bin

staging:
adapter: mysql2
Expand Down