Skip to content

Commit e0addef

Browse files
committed
Update README and install scripts
1 parent 60f21ac commit e0addef

File tree

6 files changed

+34
-71
lines changed

6 files changed

+34
-71
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ production:\n\
3131
<<: *default\n\
3232
database: tioj_production"\
3333
> config/database.yml
34-
RUN cp config/settings.yml.example config/settings.yml
3534

35+
RUN EDITOR=true rails credentials:edit
3636
RUN rails assets:precompile
3737

3838
# Move public/ to public-tmp/ since we're going to override it with 'volumes';

README.md

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ It is recommended to run this script on a freshly-installed machine. This script
1515

1616
The systemd service names are `nginx.service` and `tioj-judge.service`. The configuration files are located at `/opt/nginx/conf` and `/etc/tioj-judge.conf`. You can modify them and reload/restart the services.
1717

18-
If password recovery is needed, [setup credentials](#credentials) after the installation is completed, or pass the `SMTP_*` and `MAIL_*` environment variables to `bash` just like those in `.env.example`.
18+
If password recovery is needed, [setup the settings file](#settings) after the installation is completed, or pass the `SMTP_*` and `MAIL_*` environment variables to `bash` just like those in `.env.example`.
1919

2020
This script is tested on Ubuntu 20.04 LTS and 22.04 LTS. It also works on Arch Linux, but direct installation on Arch Linux is not recommended since it involves rebuilding some community packages for static libraries.
2121

@@ -27,31 +27,9 @@ It is strongly recommended to mount tmpfs on `/tmp` by adding `tmpfs /tmp tmpfs
2727
- The `SMTP_*` and `MAIL_*` variables are only added if password recovery function is needed. Without them, the function is automatically disabled.
2828
2. `docker-compose up -d` and enjoy TIOJ on port 4000.
2929

30-
### Credentials
31-
32-
Some settings is managed by the Rails credentials system. It can be set via `RAILS_ENV=production rails credentials:edit`. Besides `secret_key_base`, the following fields can be added to optionally enable password recovery & Sentry monitoring:
33-
34-
```yaml
35-
# Password recovery settings
36-
mail_settings:
37-
smtp_settings: # SMTP server settings; it will be passed to config.action_mailer.smtp_settings
38-
address: smtp.example.com
39-
port: 587
40-
user_name: [email protected]
41-
password: some_password
42-
enable_starttls_auto: true
43-
url_options:
44-
host: https://tioj.example.com # the URL of the website, used to generate the link in the email
45-
sender: tioj.example.com # email sender
46-
47-
# Sentry settings
48-
sentry_dsn: https://[email protected]/xxxx # copy from your sentry project
49-
```
50-
51-
## Current Development Environment
30+
### Settings
5231

53-
Ruby: 3.1.2
54-
Rails: 7.0.3
32+
If password recovery and/or Sentry monitoring is needed, setup `config/settings.yml` using the format of `config/settings.yml.example`. The old method of using `rails credentials:edit` is deprecated.
5533

5634
## Judge Management
5735

config/settings.yml.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
shared:
2+
# Omit any section if the function is not needed
3+
24
# Password recovery settings
35
mail_settings:
46
smtp_settings: # SMTP server settings; it will be passed to config.action_mailer.smtp_settings

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ services:
5252
- /srv/tioj/judge-td-pool:/var/lib/tioj-judge/td-pool
5353
- /srv/tioj/judge-testdata:/var/lib/tioj-judge/testdata
5454
tmpfs:
55-
- /tmp
55+
- /tmp:exec
5656
privileged: true
5757
network_mode: host
5858
pid: host

scripts/install.sh

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if [[ "${SMTP_USERNAME:-}" != "" && "${SMTP_PASSWORD:-}" != "" ]]; then
1313
else
1414
echo 'SMTP settings not detected. Will disable password recovery.'
1515
fi
16-
echo 'You can change this later by editing/adding/removing the `mail_settings` section in `rails credential:edit`'
16+
echo 'You can change this later by editing `config/settings.yml` according to `config/settings.yml.example`.'
1717
sleep 1
1818

1919
{ # prevent sudo timeout
@@ -136,43 +136,28 @@ production:
136136
<<: *default
137137
database: tioj_production
138138
EOF
139-
cp config/settings.yml.example config/settings.yml
140139

141140
# Setup web server
142141
FETCH_KEY=$(head -c 32 /dev/urandom | xxd -ps -c 128)
143142
export RAILS_ENV=production
144143

145-
TEMPFILE=$(mktemp)
146-
EDITOR=cat rails credentials:edit | head -n -1 | tail -n +8 > "$TEMPFILE"
147144
if [[ "${SMTP_USERNAME:-}" != "" && "${SMTP_PASSWORD:-}" != "" ]]; then
148-
cat <<EOF >> "$TEMPFILE"
149-
mail_settings:
150-
smtp_settings:
151-
address: ${SMTP_ADDRESS:-smtp.gmail.com}
152-
port: ${SMTP_PORT:-587}
153-
user_name: $SMTP_USERNAME
154-
password: $SMTP_PASSWORD
155-
enable_starttls_auto: true
156-
url_options:
157-
host: ${MAIL_HOSTNAME:-hostname}
158-
sender: ${MAIL_SENDER:-$SMTP_USERNAME}
159-
EOF
160-
else
161-
cat <<EOF >> "$TEMPFILE"
162-
#mail_settings:
163-
# smtp_settings:
164-
# address: smtp.example.com
165-
# port: 587
166-
# user_name: email_username
167-
# password: email_password
168-
# enable_starttls_auto: true
169-
# url_options:
170-
# host: http://tioj.example.com
171-
145+
cat <<EOF > config/settings.yml
146+
shared:
147+
mail_settings:
148+
smtp_settings:
149+
address: ${SMTP_ADDRESS:-smtp.gmail.com}
150+
port: ${SMTP_PORT:-587}
151+
user_name: $SMTP_USERNAME
152+
password: $SMTP_PASSWORD
153+
enable_starttls_auto: true
154+
url_options:
155+
host: ${MAIL_HOSTNAME:-hostname}
156+
sender: ${MAIL_SENDER:-$SMTP_USERNAME}
172157
EOF
173158
fi
174-
EDITOR="mv $TEMPFILE" rails credentials:edit
175159

160+
EDITOR=true rails credentials:edit
176161
rails assets:precompile
177162
TIOJ_KEY=$FETCH_KEY rails db:setup
178163

scripts/run_server.sh

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,22 @@ if [ "$1" == "1" ]; then
99
rsync -avh public-tmp/ public/
1010
rm -rf public-tmp
1111

12-
# Create credential files from environment
13-
TEMPFILE=$(mktemp)
14-
EDITOR=cat rails credentials:edit | head -n -1 | tail -n +8 > "$TEMPFILE"
12+
# Create settings file from environment
1513
if [[ "${SMTP_USERNAME:-}" != "" && "${SMTP_PASSWORD:-}" != "" ]]; then
16-
cat <<EOF >> "$TEMPFILE"
17-
mail_settings:
18-
smtp_settings:
19-
address: ${SMTP_ADDRESS:-smtp.gmail.com}
20-
port: ${SMTP_PORT:-587}
21-
user_name: $SMTP_USERNAME
22-
password: $SMTP_PASSWORD
23-
enable_starttls_auto: true
24-
url_options:
25-
host: ${MAIL_HOSTNAME:-hostname}
26-
sender: ${MAIL_SENDER:-$SMTP_USERNAME}
14+
cat <<EOF > config/settings.yml
15+
shared:
16+
mail_settings:
17+
smtp_settings:
18+
address: ${SMTP_ADDRESS:-smtp.gmail.com}
19+
port: ${SMTP_PORT:-587}
20+
user_name: $SMTP_USERNAME
21+
password: $SMTP_PASSWORD
22+
enable_starttls_auto: true
23+
url_options:
24+
host: ${MAIL_HOSTNAME:-hostname}
25+
sender: ${MAIL_SENDER:-$SMTP_USERNAME}
2726
EOF
2827
fi
29-
EDITOR="mv $TEMPFILE" rails credentials:edit
3028
fi
3129
until timeout 2s nc -z db 3306; do
3230
sleep 1

0 commit comments

Comments
 (0)