Dokku deploy setup (#1)

* fix: remove config.key from Dockerfile

* refactor: remove redis

* chore: update README

* feat: precompile assets on build Dockerfile
This commit is contained in:
Juan Rodriguez
2023-03-26 19:00:09 +02:00
committed by GitHub
parent 38ce72618a
commit 63acab3cf7
9 changed files with 50 additions and 45 deletions
+8 -8
View File
@@ -1,13 +1,15 @@
FROM ruby:2.6.3-alpine
ARG RAILS_MASTER_KEY=''
ENV RAILS_MASTER_KEY ${RAILS_MASTER_KEY}
ENV RAILS_ENV production
ENV APP_PATH /usr/src/app
ENV BUNDLE_VERSION 2.1.4
ENV RAILS_LOG_TO_STDOUT true
ENV RAILS_ENV production
WORKDIR $APP_PATH
EXPOSE $RAILS_PORT
EXPOSE 3000
ENV ALPINE_MIRROR "http://dl-cdn.alpinelinux.org/alpine"
RUN echo "${ALPINE_MIRROR}/v3.11/main/" >> /etc/apk/repositories
@@ -30,17 +32,15 @@ RUN gem install bundler --version "$BUNDLE_VERSION"
COPY ./Gemfile .
COPY ./Gemfile.lock .
RUN bundle install --jobs 20 --retry 5
RUN bundle install --binstubs
COPY ./package.json .
COPY ./yarn.lock .
RUN yarn
RUN yarn --production
COPY . .
RUN chmod 600 config/master.key
RUN bundle exec rails assets:precompile
CMD ["bundle", "exec", "rails", "s", "-b", "0.0.0.0"]
CMD ["bundle", "exec", "rails", "s", "-b", "0.0.0.0"]
+1 -1
View File
@@ -23,7 +23,7 @@ gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
gem 'redis', '~> 4.0'
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
+1 -3
View File
@@ -152,7 +152,6 @@ GEM
rb-fsevent (0.11.0)
rb-inotify (0.10.1)
ffi (~> 1.0)
redis (4.3.1)
regexp_parser (2.1.1)
rexml (3.2.5)
rubocop (1.17.0)
@@ -250,7 +249,6 @@ DEPENDENCIES
pg (>= 0.18, < 2.0)
puma (~> 4.3.8)
rails (~> 5.2.6)
redis (~> 4.0)
rubocop (~> 1.17)
rubocop-rails
selenium-webdriver
@@ -268,4 +266,4 @@ RUBY VERSION
ruby 2.6.3p62
BUNDLED WITH
2.1.4
2.1.4 2.1.4
+33 -24
View File
@@ -1,8 +1,27 @@
# URL shortener
## How to run
<p align="center">
<img width="600" alt="image" src="https://user-images.githubusercontent.com/27580836/227785266-40a0bb04-0f19-4f3e-9831-b74464848d99.png">
</p>
### Development
# Features
- [x] Create link model (make sure to create a index for the slug and click counter)
- [x] Generate unique slug
- [x] Link unit tests
- [x] Stimulus setup
- [x] Link controller (handle redirection)
- [x] Main page with input box
- [x] Create user model
- [x] User unit tests
- [x] Add userId key to link model
- [x] Login and logout (sessions)
- [x] User links view
- [x] Modals layout
- [x] Deployment CI
# How to run
## Development
- Run migrations
```bash
docker-compose up -d db
@@ -13,19 +32,19 @@ docker-compose run --rm app bundle exec rails db:migrate
docker-compose up
```
### Testing
## Testing
```bash
docker-compose run --rm app bundle exec rails test
```
### Rubocop
## Rubocop
```bash
docker-compose run --rm app bundle exec rubocop
```
## Results
# Results
- Testing
## Testing
```bash
Finished in 2.211344s, 9.9487 runs/s, 10.4009 assertions/s.
22 runs, 23 assertions, 0 failures, 0 errors, 0 skips
@@ -48,7 +67,7 @@ BRANCH COVERAGE: 100.00% -- 20/20 branches in 8 branches
+----------+-------------------------------------------+-------+--------+---------+-----------------+----------+-----------------+------------------+
```
- Rubocop
## Rubocop
```bash
Inspecting 43 files
...........................................
@@ -56,21 +75,11 @@ Inspecting 43 files
43 files inspected, no offenses detected
```
- Production link
https://s-shortener.herokuapp.com/
- Dokku deployment
```bash
bundle exec rails assets:precompile
bundle exec rails db:migrate
```
## TODO
- [x] Create link model (make sure to create a index for the slug and click counter)
- [x] Generate unique slug
- [x] Link unit tests
- [x] Stimulus setup
- [x] Link controller (handle redirection)
- [x] Main page with input box
- [x] Create user model
- [x] User unit tests
- [x] Add userId key to link model
- [x] Login and logout (sessions)
- [x] User links view
- [x] Modals layout
- [x] Setup Redis for production cache_store
- [x] Deployment CI
- Production link
https://url-shortener.sjdonado.de
+1 -3
View File
@@ -5,6 +5,4 @@ test:
adapter: async
production:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: app_production
adapter: async
+1 -1
View File
@@ -1 +1 @@
ixtsTt2O/bqumywSaldHxkihLw2+zumFOL1B0NtK6lQ460IU6WZsnEFc02muVzP5t4Rn3zyZjaP74fZEgxqfRELE8pffCZTHCkaPeaeULgqwQJy9OVAkd0SHN0k8jRlFtNFKQvrzE7ngnbO+eX9ZwlotQlaUxAlSrOJ9av7OaRwCfMpMgjVbKZfxJvhFW0l+twV8hjdyXbuFuoS8g3VrsaEYvZOu+zz0QMwgK5WmOIQbvwn/VSWWHkRraPGPm+xpUyi8UmAVFjdT02zSEaaauaRhtSSNGz5ufYEPZMrs99iKw/HFpkUHs+R0tqafFT2CBw7ai+h9i/ZblYppJDw5PpnoqY/kneBsz2NT+a0eyL7ZS9YJit+M77Z40gULUapc03SzRlAXy3rrkVFGqIaHSKibOKfpn/KbL9D+--2hixMh1aBR3PcnjL--Tzv9NyC3MTTMHYHn8u5Lhw==
Wk6KXgfCMEdFwrlXhheO89gYdFLEemFYnWBHSKZ7rw73RRoHvVypao5sjPXsKEBG8yOfS2wHMf13VMcfWhGHX9ZJrm+Dav/QRz3cNkaJ2RLmgBDp0vjGpYQ4bQxJSHILYxFD6paiyrS89VsfM5yTl+Zmhhg1Kjc2DFeY6KClLAT+84rWkd+BoTb4VSLcP0RYLStvITr4G66SEDN3pUdoOgcHqCHDYsNZPhSQjkSOHftCjcHziIgHZmhboj6gMNk7R6mVhNc5mhhg68WuhXOR2UCdebxAGDKAtRjqSGWv0A6kwMO1yFQDRdYnURjKJCQxNACqd8XNh5hLuLvpeV04E6SivbF7uIapwtQdjL3Tq1+mSaGeYqduPpSSFiizINJa459Q6qxc2gev/pgPvY8vdwB/iMQznUj3he6Q--aLOyL+GzKtf/En3Q--pI05hACTxEqi2bHlVD6QGg==
+2 -2
View File
@@ -18,7 +18,7 @@ Rails.application.configure do
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
# config.require_master_key = true
config.require_master_key = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
@@ -58,7 +58,7 @@ Rails.application.configure do
# Prepend all log lines with the following tags.
config.log_tags = [:request_id]
config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL'] }
config.cache_store = :memory_store
# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
+1 -1
View File
@@ -83,7 +83,7 @@ production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
compile: true
# Extract and emit a css file
extract_css: true
+2 -2
View File
@@ -2,6 +2,6 @@
set -e
rm -f $APP_PATH/tmp/pids/server.pid
rm -f "$APP_PATH/tmp/pids/server.pid"
${@}
"${@}"