Skip to content

Commit

Permalink
Working docker deploy of app
Browse files Browse the repository at this point in the history
  • Loading branch information
pwnpanda committed Apr 3, 2021
1 parent 60d0852 commit 056f9af
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 69 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
*.ap_
*.aab

#environment files
.env

#secret
WebAPI/secret.txt

# Files for the ART/Dalvik VM
*.dex

Expand Down
18 changes: 17 additions & 1 deletion WebAPI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,20 @@ Follow (this article)[https://medium.com/@mshostdrive/how-to-run-a-rails-app-in-
- `RAILS_ENV=production rake db:create db:migrate db:seed`
- Copy output from: `rake secret`
- `export SECRET_KEY_BASE=<output-of-rake-secret>`
- `RAILS_ENV=production rails s`
- `RAILS_ENV=production rails s`
- `rails s -p 12121 -b 127.0.0.1 -e production`

### Docker
- Build image: `docker build --tag mail_api:latest .`
- Cleanup previous fragments `docker ps -aq --filter "name=mail_api"|grep -q . && docker stop mail_api && docker container rm -fv mail_api || true`
- Start new instance `docker run --name mail_api -d=true -v mail_api_db:/mail_api/db/ -p 12121:12121 mail_api:latest`

- To persist storage:
* create volume: `docker volume create mail_api_db`
* Use volume (as seen above)
* FInd real location: `docker volume inspect mail_api_db`
* Copy from that location to backup spot

- Easy mode:
- put secret in "secret.txt" with dockerfile and docker-compse.yml
- docker-compose up -d -u "www-data"
20 changes: 20 additions & 0 deletions WebAPI/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: "3.8"
services:
web:
build: .
working_dir: /mail_api
volumes:
- "mail_api_db:/mail_api/db"
ports:
- "12121:12121"
environment:
SECRET_KEY_BASE: /run/secrets/mail_api_secret
secrets:
- mail_api_secret

secrets:
mail_api_secret:
file: secret.txt

volumes:
mail_api_db:
20 changes: 20 additions & 0 deletions WebAPI/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from ruby:3.0.0 as runtime

#RUN bundle config --global frozen 1
RUN apt-get update -y && apt-get upgrade -y

WORKDIR mail_api/

copy mail_api/ ./

ENV BUNDLER_VERSION=2.2.3

RUN gem update --system
RUN gem install rails
RUN gem install bundler -v 2.2.3
RUN bundle install
RUN rake app:update:bin

EXPOSE 12121
ENV RAILS_ENV=production
ENTRYPOINT ["rails", "s", "-p", "12121", "-b", "0.0.0.0", "-e", "production"]
2 changes: 1 addition & 1 deletion WebAPI/mail_api/.ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.5.1
ruby-3.0.0
2 changes: 1 addition & 1 deletion WebAPI/mail_api/Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.5.1'
ruby '3.0.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.3'
Expand Down
130 changes: 64 additions & 66 deletions WebAPI/mail_api/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (6.1.3)
actionpack (= 6.1.3)
activesupport (= 6.1.3)
actioncable (6.1.3.1)
actionpack (= 6.1.3.1)
activesupport (= 6.1.3.1)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.1.3)
actionpack (= 6.1.3)
activejob (= 6.1.3)
activerecord (= 6.1.3)
activestorage (= 6.1.3)
activesupport (= 6.1.3)
actionmailbox (6.1.3.1)
actionpack (= 6.1.3.1)
activejob (= 6.1.3.1)
activerecord (= 6.1.3.1)
activestorage (= 6.1.3.1)
activesupport (= 6.1.3.1)
mail (>= 2.7.1)
actionmailer (6.1.3)
actionpack (= 6.1.3)
actionview (= 6.1.3)
activejob (= 6.1.3)
activesupport (= 6.1.3)
actionmailer (6.1.3.1)
actionpack (= 6.1.3.1)
actionview (= 6.1.3.1)
activejob (= 6.1.3.1)
activesupport (= 6.1.3.1)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.1.3)
actionview (= 6.1.3)
activesupport (= 6.1.3)
actionpack (6.1.3.1)
actionview (= 6.1.3.1)
activesupport (= 6.1.3.1)
rack (~> 2.0, >= 2.0.9)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.1.3)
actionpack (= 6.1.3)
activerecord (= 6.1.3)
activestorage (= 6.1.3)
activesupport (= 6.1.3)
actiontext (6.1.3.1)
actionpack (= 6.1.3.1)
activerecord (= 6.1.3.1)
activestorage (= 6.1.3.1)
activesupport (= 6.1.3.1)
nokogiri (>= 1.8.5)
actionview (6.1.3)
activesupport (= 6.1.3)
actionview (6.1.3.1)
activesupport (= 6.1.3.1)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.1.3)
activesupport (= 6.1.3)
activejob (6.1.3.1)
activesupport (= 6.1.3.1)
globalid (>= 0.3.6)
activemodel (6.1.3)
activesupport (= 6.1.3)
activerecord (6.1.3)
activemodel (= 6.1.3)
activesupport (= 6.1.3)
activestorage (6.1.3)
actionpack (= 6.1.3)
activejob (= 6.1.3)
activerecord (= 6.1.3)
activesupport (= 6.1.3)
marcel (~> 0.3.1)
mimemagic (~> 0.3.2)
activesupport (6.1.3)
activemodel (6.1.3.1)
activesupport (= 6.1.3.1)
activerecord (6.1.3.1)
activemodel (= 6.1.3.1)
activesupport (= 6.1.3.1)
activestorage (6.1.3.1)
actionpack (= 6.1.3.1)
activejob (= 6.1.3.1)
activerecord (= 6.1.3.1)
activesupport (= 6.1.3.1)
marcel (~> 1.0.0)
mini_mime (~> 1.0.2)
activesupport (6.1.3.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
bootsnap (1.7.2)
bootsnap (1.7.3)
msgpack (~> 1.0)
builder (3.2.4)
byebug (11.1.3)
Expand All @@ -70,48 +70,46 @@ GEM
ffi (1.15.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.8.9)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
jbuilder (2.11.2)
activesupport (>= 5.0.0)
listen (3.4.1)
listen (3.5.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.9.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
marcel (1.0.1)
method_source (1.0.0)
mimemagic (0.3.5)
mini_mime (1.0.2)
mini_mime (1.0.3)
minitest (5.14.4)
msgpack (1.4.2)
nio4r (2.5.7)
nokogiri (1.11.2-x86_64-linux)
nokogiri (1.11.2-x86_64-darwin)
racc (~> 1.4)
puma (5.2.2)
nio4r (~> 2.0)
racc (1.5.2)
rack (2.2.3)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.1.3)
actioncable (= 6.1.3)
actionmailbox (= 6.1.3)
actionmailer (= 6.1.3)
actionpack (= 6.1.3)
actiontext (= 6.1.3)
actionview (= 6.1.3)
activejob (= 6.1.3)
activemodel (= 6.1.3)
activerecord (= 6.1.3)
activestorage (= 6.1.3)
activesupport (= 6.1.3)
rails (6.1.3.1)
actioncable (= 6.1.3.1)
actionmailbox (= 6.1.3.1)
actionmailer (= 6.1.3.1)
actionpack (= 6.1.3.1)
actiontext (= 6.1.3.1)
actionview (= 6.1.3.1)
activejob (= 6.1.3.1)
activemodel (= 6.1.3.1)
activerecord (= 6.1.3.1)
activestorage (= 6.1.3.1)
activesupport (= 6.1.3.1)
bundler (>= 1.15.0)
railties (= 6.1.3)
railties (= 6.1.3.1)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
Expand All @@ -123,9 +121,9 @@ GEM
rails_stdout_logging
rails_serve_static_assets (0.0.5)
rails_stdout_logging (0.0.5)
railties (6.1.3)
actionpack (= 6.1.3)
activesupport (= 6.1.3)
railties (6.1.3.1)
actionpack (= 6.1.3.1)
activesupport (= 6.1.3.1)
method_source
rake (>= 0.8.7)
thor (~> 1.0)
Expand All @@ -151,7 +149,7 @@ GEM
zeitwerk (2.4.2)

PLATFORMS
x86_64-linux
x86_64-darwin-19

DEPENDENCIES
bootsnap (>= 1.4.4)
Expand All @@ -166,7 +164,7 @@ DEPENDENCIES
tzinfo-data

RUBY VERSION
ruby 2.5.1p57
ruby 3.0.0p0

BUNDLED WITH
2.2.15
2.2.3

0 comments on commit 056f9af

Please sign in to comment.