This repository has been archived by the owner on Nov 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: update osm entrypoint to be idempotent + output oauth secret
- Loading branch information
1 parent
cb3db92
commit 027da59
Showing
1 changed file
with
42 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
#!/bin/bash | ||
|
||
# Start web server | ||
# First start web server & run migrations | ||
bundle exec rails s -d -p 3000 -b '0.0.0.0' | ||
|
||
# Run migrations | ||
bundle exec rails db:migrate | ||
|
||
# Ruby script to create admin (to file) | ||
|
@@ -37,12 +35,16 @@ unless Oauth2Application.exists?(name: 'ID Dev') | |
confidential: false, | ||
) | ||
puts id_app.uid | ||
# puts id_app.secret | ||
puts id_app.secret | ||
end | ||
EOF | ||
|
||
# Run script in Rails console | ||
ID_EDITOR_CLIENT_ID=$(bundle exec rails runner create_admin_user.rb) | ||
# Add output from Rails script to file, then extract OAuth app creds | ||
if [ ! -e /tmp/create_admin_user.log ]; then | ||
bundle exec rails runner create_admin_user.rb > /tmp/create_admin_user.log | ||
ID_EDITOR_CLIENT_ID=$(sed -n '1p' /tmp/create_admin_user.log) | ||
ID_EDITOR_CLIENT_SECRET=$(sed -n '2p' /tmp/create_admin_user.log) | ||
fi | ||
|
||
# Stop web server gracefully | ||
kill -TERM $(cat /tmp/pids/server.pid) | ||
|
@@ -51,14 +53,40 @@ kill -TERM $(cat /tmp/pids/server.pid) | |
# Further overrides can be made in a mounted settings.local.yml file | ||
# The oauth_application var is for OSM Notes / changeset comments | ||
# The id_application var is for ID editor | ||
sed -i "s/#id_application: \"\"/id_application: \"${ID_EDITOR_CLIENT_ID}\"/" /app/config/settings.yml | ||
sed -i "s/server_protocol: \"http\"/server_protocol: \"${PROTOCOL}\"/" /app/config/settings.yml | ||
sed -i "s/server_url: \"openstreetmap.example.com\"/server_url: \"${DOMAIN}\"/" /app/config/settings.yml | ||
if ! grep -q "id_application: \"${ID_EDITOR_CLIENT_ID}\"" /app/config/settings.yml; then | ||
sed -i "s/#id_application: \"\"/id_application: \"${ID_EDITOR_CLIENT_ID}\"/" /app/config/settings.yml | ||
fi | ||
|
||
if ! grep -q "server_protocol: \"${PROTOCOL}\"" /app/config/settings.yml; then | ||
sed -i "s/server_protocol: \"http\"/server_protocol: \"${PROTOCOL}\"/" /app/config/settings.yml | ||
fi | ||
|
||
if ! grep -q "server_url: \"${DOMAIN}\"" /app/config/settings.yml; then | ||
sed -i "s/server_url: \"openstreetmap.example.com\"/server_url: \"${DOMAIN}\"/" /app/config/settings.yml | ||
fi | ||
|
||
# SMTP settings | ||
sed -i "s/smtp_address: \"localhost\"/smtp_address: \"mail\"/" /app/config/settings.yml | ||
sed -i "s/smtp_domain: \"localhost\"/smtp_domain: \"${DOMAIN}\"/" /app/config/settings.yml | ||
sed -i "s/email_from: \"OpenStreetMap <[email protected]>\"/email_from: \"HOTOSM Sandbox <no-reply@${DOMAIN}>\"/" /app/config/settings.yml | ||
sed -i "s/email_return_path: \"[email protected]\"/email_return_path: \"no-reply@${DOMAIN}\"/" /app/config/settings.yml | ||
if ! grep -q "smtp_address: \"mail\"" /app/config/settings.yml; then | ||
sed -i "s/smtp_address: \"localhost\"/smtp_address: \"mail\"/" /app/config/settings.yml | ||
fi | ||
|
||
if ! grep -q "smtp_domain: \"${DOMAIN}\"" /app/config/settings.yml; then | ||
sed -i "s/smtp_domain: \"localhost\"/smtp_domain: \"${DOMAIN}\"/" /app/config/settings.yml | ||
fi | ||
|
||
if ! grep -q "email_from: \"HOTOSM Sandbox <no-reply@${DOMAIN}>\"" /app/config/settings.yml; then | ||
sed -i "s/email_from: \"OpenStreetMap <[email protected]>\"/email_from: \"HOTOSM Sandbox <no-reply@${DOMAIN}>\"/" /app/config/settings.yml | ||
fi | ||
|
||
if ! grep -q "email_return_path: \"no-reply@${DOMAIN}\"" /app/config/settings.yml; then | ||
sed -i "s/email_return_path: \"[email protected]\"/email_return_path: \"no-reply@${DOMAIN}\"/" /app/config/settings.yml | ||
fi | ||
|
||
echo | ||
echo "ID Editor OAuth App Details:" | ||
echo | ||
echo "Client ID: $ID_EDITOR_CLIENT_ID" | ||
echo "Client Secret: $ID_EDITOR_CLIENT_SECRET" | ||
echo | ||
|
||
# Set exec to replace shell with the command passed as arguments | ||
exec "$@" |