ci: 👷 Github actions setup, heroku deployment
Redis cache store, Production Dockerfile, Github actions workflow
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
name: Deploy production to Heroku
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@master
|
||||
- name: Login to Heroku
|
||||
run: heroku container:login
|
||||
env:
|
||||
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
|
||||
- name: Build and push
|
||||
run: heroku container:push -a $APP_NAME web
|
||||
env:
|
||||
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
|
||||
APP_NAME: s-shortener
|
||||
- name: Release
|
||||
run: heroku container:release -a $APP_NAME web
|
||||
env:
|
||||
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
|
||||
APP_NAME: s-shortener
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
FROM ruby:2.6.3-alpine
|
||||
|
||||
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
|
||||
|
||||
ENV ALPINE_MIRROR "http://dl-cdn.alpinelinux.org/alpine"
|
||||
RUN echo "${ALPINE_MIRROR}/v3.11/main/" >> /etc/apk/repositories
|
||||
|
||||
RUN apk -U add --no-cache \
|
||||
build-base \
|
||||
postgresql-dev \
|
||||
postgresql-client \
|
||||
tzdata \
|
||||
nodejs --repository="http://dl-cdn.alpinelinux.org/alpine/v3.11/main/" \
|
||||
yarn
|
||||
|
||||
COPY ./entrypoint.sh /usr/bin/entrypoint.sh
|
||||
RUN chmod +x /usr/bin/entrypoint.sh
|
||||
|
||||
RUN gem install bundler --version "$BUNDLE_VERSION"
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN bundle install --jobs 20 --retry 5
|
||||
|
||||
RUN yarn
|
||||
|
||||
ENTRYPOINT ["entrypoint.sh"]
|
||||
|
||||
CMD ["rails", "s", "-b", "0.0.0.0"]
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
FROM ruby:2.6.3-alpine
|
||||
|
||||
ENV APP_PATH /usr/src/app
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
@@ -147,6 +147,7 @@ GEM
|
||||
rb-fsevent (0.11.0)
|
||||
rb-inotify (0.10.1)
|
||||
ffi (~> 1.0)
|
||||
redis (4.3.1)
|
||||
regexp_parser (2.1.1)
|
||||
ruby_dep (1.5.0)
|
||||
rubyzip (2.3.0)
|
||||
@@ -227,6 +228,7 @@ DEPENDENCIES
|
||||
pg (>= 0.18, < 2.0)
|
||||
puma (~> 4.3.8)
|
||||
rails (~> 5.2.6)
|
||||
redis (~> 4.0)
|
||||
selenium-webdriver
|
||||
simplecov
|
||||
simplecov-console
|
||||
|
||||
@@ -23,6 +23,45 @@ docker-compose run --rm app bundle exec rails test
|
||||
docker-compose run --rm app rubocop
|
||||
```
|
||||
|
||||
## Results
|
||||
|
||||
- Testing
|
||||
```bash
|
||||
Finished in 2.227992s, 10.3232 runs/s, 10.7720 assertions/s.
|
||||
23 runs, 24 assertions, 0 failures, 0 errors, 0 skips
|
||||
Coverage report generated for Minitest to /usr/src/app/coverage. 77 / 77 LOC (100.0%) covered.
|
||||
|
||||
COVERAGE: 100.00% -- 77/77 lines in 11 files
|
||||
BRANCH COVERAGE: 100.00% -- 20/20 branches in 11 branches
|
||||
|
||||
+----------+-------------------------------------------+-------+--------+---------+-----------------+----------+-----------------+------------------+
|
||||
| coverage | file | lines | missed | missing | branch coverage | branches | branches missed | branches missing |
|
||||
+----------+-------------------------------------------+-------+--------+---------+-----------------+----------+-----------------+------------------+
|
||||
| 100.00% | app/controllers/application_controller.rb | 2 | 0 | | 100.00% | 0 | 0 | |
|
||||
| 100.00% | app/controllers/links_controller.rb | 22 | 0 | | 100.00% | 8 | 0 | |
|
||||
| 100.00% | app/controllers/sessions_controller.rb | 14 | 0 | | 100.00% | 4 | 0 | |
|
||||
| 100.00% | app/controllers/users_controller.rb | 12 | 0 | | 100.00% | 4 | 0 | |
|
||||
| 100.00% | app/helpers/application_helper.rb | 1 | 0 | | 100.00% | 0 | 0 | |
|
||||
| 100.00% | app/helpers/links_helper.rb | 1 | 0 | | 100.00% | 0 | 0 | |
|
||||
| 100.00% | app/helpers/sessions_helper.rb | 7 | 0 | | 100.00% | 2 | 0 | |
|
||||
| 100.00% | app/helpers/users_helper.rb | 1 | 0 | | 100.00% | 0 | 0 | |
|
||||
| 100.00% | app/models/application_record.rb | 2 | 0 | | 100.00% | 0 | 0 | |
|
||||
| 100.00% | app/models/link.rb | 11 | 0 | | 100.00% | 2 | 0 | |
|
||||
| 100.00% | app/models/user.rb | 4 | 0 | | 100.00% | 0 | 0 | |
|
||||
+----------+-------------------------------------------+-------+--------+---------+-----------------+----------+-----------------+------------------+
|
||||
```
|
||||
|
||||
- Rubocop
|
||||
```bash
|
||||
Inspecting 58 files
|
||||
..........................................................
|
||||
|
||||
58 files inspected, no offenses detected
|
||||
```
|
||||
|
||||
- Production link
|
||||
https://s-shortener.herokuapp.com/
|
||||
|
||||
## TODO
|
||||
- [x] Create link model (make sure to create a index for the slug and click counter)
|
||||
- [x] Generate unique slug
|
||||
@@ -36,5 +75,5 @@ docker-compose run --rm app rubocop
|
||||
- [x] Login and logout (sessions)
|
||||
- [x] User links view
|
||||
- [x] Modals layout
|
||||
- [ ] Setup Redis for production cache_store
|
||||
- [ ] Deployment CI
|
||||
- [x] Setup Redis for production cache_store
|
||||
- [x] Deployment CI
|
||||
@@ -58,8 +58,7 @@ Rails.application.configure do
|
||||
# Prepend all log lines with the following tags.
|
||||
config.log_tags = [:request_id]
|
||||
|
||||
# Use a different cache store in production.
|
||||
# config.cache_store = :mem_cache_store
|
||||
config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL'] }
|
||||
|
||||
# Use a real queuing backend for Active Job (and separate queues per environment)
|
||||
# config.active_job.queue_adapter = :resque
|
||||
@@ -94,5 +93,5 @@ Rails.application.configure do
|
||||
# Do not dump schema after migrations.
|
||||
config.active_record.dump_schema_after_migration = false
|
||||
|
||||
Rails.application.routes.default_url_options[:host] = "#{ENV['HOSTNAME']}:#{ENV['RAILS_PORT']}"
|
||||
Rails.application.routes.default_url_options[:host] = ENV['HOSTNAME']
|
||||
end
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
rm -f $APP_PATH/tmp/pids/server.pid
|
||||
|
||||
${@}
|
||||
Reference in New Issue
Block a user