Skip to content

Commit

Permalink
Fix migration and add pregenerated SSL as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvel committed Nov 28, 2023
1 parent 10f2c5c commit 09f32dd
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 34 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ RUN rm -f db/development*
EXPOSE 9292

ENV RACK_ENV=production
ENV TUDUDI_INTERNAL_SSL_ENABLED=false

RUN mkdir -p certs && \
openssl req -x509 -newkey rsa:4096 -keyout certs/server.key -out certs/server.crt -days 365 -nodes -subj '/CN=localhost'
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ puma -C app/config/puma.rb
Pull the latest image:

```bash
docker pull chrisvel/tududi:0.15
docker pull chrisvel/tududi:0.16
```

In order to start the docker container you need 3 enviromental variables:
Expand All @@ -100,24 +100,27 @@ In order to start the docker container you need 3 enviromental variables:
TUDUDI_USER_EMAIL
TUDUDI_USER_PASSWORD
TUDUDI_SESSION_SECRET
TUDUDI_INTERNAL_SSL_ENABLED
```

**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`:
1. (optional) Create a random session secret and copy the hash to use it as a `TUDUDI_SESSION_SECRET`:
```bash
openssl rand -hex 64
```
You will also have to set `TUDUDI_INTERNAL_SSL_ENABLED=true` in the docker command below.

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 \
-e TUDUDI_INTERNAL_SSL_ENABLED=false \
-v ~/tududi_db:/usr/src/app/tududi_db \
-p 9292:9292 \
-d chrisvel/tududi:0.15
-d chrisvel/tududi:0.16
```

3. Navigate to https://localhost:9292 and fill in your email and password.
Expand Down
14 changes: 9 additions & 5 deletions app/config/puma.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
ssl_bind '0.0.0.0', '9292', {
key: 'certs/server.key',
cert: 'certs/server.crt',
verify_mode: 'none'
}
if ENV['TUDUDI_INTERNAL_SSL_ENABLED'] == 'true'
ssl_bind '0.0.0.0', '9292', {
key: 'certs/server.key',
cert: 'certs/server.crt',
verify_mode: 'none'
}
else
bind 'tcp://0.0.0.0:9292'
end
36 changes: 16 additions & 20 deletions db/migrate/20231127092131_change_priority_in_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ class ChangePriorityInTasks < ActiveRecord::Migration[7.1]
def up
add_column :tasks, :new_priority, :integer

Task.reset_column_information
Task.find_each do |task|
new_value = case task.priority
when 'Low' then 0
when 'Medium' then 1
when 'High' then 2
else 0
end
task.update_column(:new_priority, new_value)
end
execute <<-SQL.squish
UPDATE tasks SET new_priority = CASE
WHEN priority = 'Low' THEN 0
WHEN priority = 'Medium' THEN 1
WHEN priority = 'High' THEN 2
ELSE 0
END
SQL

remove_column :tasks, :priority
rename_column :tasks, :new_priority, :priority
Expand All @@ -20,16 +18,14 @@ def up
def down
add_column :tasks, :old_priority, :string

Task.reset_column_information
Task.find_each do |task|
old_value = case task.priority
when 0 then 'Low'
when 1 then 'Medium'
when 2 then 'High'
else 'Low'
end
task.update_column(:old_priority, old_value)
end
execute <<-SQL.squish
UPDATE tasks SET old_priority = CASE
WHEN priority = 0 THEN 'Low'
WHEN priority = 1 THEN 'Medium'
WHEN priority = 2 THEN 'High'
ELSE 'Low'
END
SQL

remove_column :tasks, :priority
rename_column :tasks, :old_priority, :priority
Expand Down
16 changes: 10 additions & 6 deletions db/migrate/20231127094906_add_note_and_status_to_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ def up
add_column :tasks, :note, :text
add_column :tasks, :status, :integer, default: 0

Task.reset_column_information
Task.find_each do |task|
task.update_column(:status, task.completed ? 2 : 0)
end
execute <<-SQL.squish
UPDATE tasks SET status = CASE
WHEN completed = 't' THEN 2
ELSE 0
END
SQL

remove_column :tasks, :completed
end

def down
add_column :tasks, :completed, :boolean, default: false

Task.reset_column_information
Task.where(status: 2).update_all(completed: true)
execute <<-SQL.squish
UPDATE tasks SET completed = 't'
WHERE status = 2
SQL

remove_column :tasks, :status
remove_column :tasks, :note
Expand Down

0 comments on commit 09f32dd

Please sign in to comment.