Add docker instructions
This commit is contained in:
parent
8995a6b943
commit
cc3399c363
4 changed files with 68 additions and 4 deletions
5
.dockerignore
Normal file
5
.dockerignore
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
*.sqlite3
|
||||
*.sqlite3-shm
|
||||
*.sqlite3-wal
|
||||
certs/
|
||||
.DS_Store
|
||||
22
Dockerfile
Normal file
22
Dockerfile
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
FROM ruby:3.2.2-slim
|
||||
|
||||
RUN apt-get update -qq && apt-get install -y build-essential libsqlite3-dev openssl
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY Gemfile* ./
|
||||
|
||||
RUN bundle config set without 'development test' && bundle install
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 9292
|
||||
|
||||
ENV RACK_ENV=production
|
||||
|
||||
RUN mkdir -p certs && \
|
||||
openssl req -x509 -newkey rsa:4096 -keyout certs/server.key -out certs/server.crt -days 365 -nodes -subj '/CN=localhost'
|
||||
|
||||
RUN rake db:migrate
|
||||
|
||||
CMD ["puma", "-C", "app/config/puma.rb"]
|
||||
30
README.md
30
README.md
|
|
@ -83,6 +83,36 @@ To start the application, run the following command in your terminal:
|
|||
puma -C app/config/puma.rb
|
||||
```
|
||||
|
||||
### Docker
|
||||
|
||||
In order to start the docker container you need 3 enviromental variables:
|
||||
|
||||
```bash
|
||||
TUDUDI_USER_EMAIL
|
||||
TUDUDI_USER_PASSWORD
|
||||
TUDUDI_SESSION_SECRET
|
||||
```
|
||||
|
||||
**PLEASE NOTE:** I am generating a new SSL certificate inside the Dockerfile. There will be an option to create and link an externally generated one in the future - at this stage I am doing this for simplicity.
|
||||
|
||||
1. Create a random session secret and copy the hash to use it as a `TUDUDI_SESSION_SECRET`:
|
||||
```bash
|
||||
openssl rand -hex 64
|
||||
```
|
||||
|
||||
2. Run the docker command with your produced hash at the previous step:
|
||||
```bash
|
||||
docker run -e TUDUDI_USER_EMAIL=myemail@example.com
|
||||
-e TUDUDI_USER_PASSWORD=mysecurepassword
|
||||
-e TUDUDI_SESSION_SECRET=3337c138d17ac7acefa412e5db0d7ef6540905b198cc28c5bf0d11e48807a71bdfe48d82ed0a0a6eb667c937cbdd1db3e1e6073b3148bff37f73cc6398a39671
|
||||
-v ~/tududi_db:/db
|
||||
-p 9292:9292
|
||||
-d tududi
|
||||
```
|
||||
|
||||
3. Navigate to https://localhost:9292 and fill in your email and password.
|
||||
4. Enjoy
|
||||
|
||||
### Testing
|
||||
|
||||
To run tests:
|
||||
|
|
|
|||
15
app.rb
15
app.rb
|
|
@ -25,9 +25,16 @@ set :public_folder, 'public'
|
|||
configure do
|
||||
enable :sessions
|
||||
set :sessions, httponly: true, secure: production?, expire_after: 2_592_000
|
||||
set :session_secret, ENV.fetch('SESSION_SECRET') { SecureRandom.hex(64) }
|
||||
set :session_secret,
|
||||
'740cca863278d6cbacb64dbdd41cfdb1598e8208ce9b9d29b0a1e7c1e1367ca1241d8048849ee88784731d43879c94f5b9f0a639135828d590a447acb2d98e1c'
|
||||
set :session_secret, ENV.fetch('TUDUDI_SESSION_SECRET') { SecureRandom.hex(64) }
|
||||
|
||||
# Auto-create user if not exists
|
||||
if ENV['TUDUDI_USER_EMAIL'] && ENV['TUDUDI_USER_PASSWORD']
|
||||
user = User.find_or_initialize_by(email: ENV['TUDUDI_USER_EMAIL'])
|
||||
if user.new_record?
|
||||
user.password = ENV['TUDUDI_USER_PASSWORD']
|
||||
user.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
use Rack::Protection
|
||||
|
|
@ -85,4 +92,4 @@ end
|
|||
|
||||
get '/inbox' do
|
||||
erb :inbox
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue