Skip to content

Commit 2690fff

Browse files
init dev setup with codespaces (#495)
* init dev setup with codespaces * add a codespace setup script for setting up postgres * added copying env to script
1 parent 4076b42 commit 2690fff

6 files changed

Lines changed: 88 additions & 29 deletions

File tree

.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copy this file to .env and fill in values for your local setup.
2+
3+
POSTGRES_HOST=127.0.0.1
4+
POSTGRES_PORT=5432
5+
POSTGRES_USER=postgres
6+
POSTGRES_PASSWORD=postgres
7+
POSTGRES_DATABASE=calendar_development
8+
POSTGRES_TEST_DATABASE=calendar_test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
# Ignore all environment files.
1111
/.env*
12+
!/.env.example
1213

1314
# Ignore all logfiles and tempfiles.
1415
/log/*
@@ -54,3 +55,5 @@ public/*.webp
5455
!/app/assets/builds/.keep
5556

5657
config/credentials/
58+
/.postgres-data
59+
/.postgres-socket

Gemfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ gem "console1984"
3030

3131
gem "bootsnap", require: false
3232
gem "thruster", require: false
33-
gem "image_processing", "~> 2.0"
34-
gem "ruby-vips"
33+
# gem "image_processing", "~> 2.0"
34+
# gem "ruby-vips"
3535

3636
# Authentication
3737
gem "devise", "~> 5.0"
@@ -83,6 +83,7 @@ group :development, :test do
8383
gem "rspec-rails"
8484
gem "factory_bot_rails"
8585
gem "faker"
86+
gem "dotenv-rails"
8687
end
8788

8889
group :development do

Gemfile.lock

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ GEM
139139
responders
140140
warden (~> 1.2.3)
141141
diff-lcs (1.6.2)
142+
dotenv (3.2.0)
143+
dotenv-rails (3.2.0)
144+
dotenv (= 3.2.0)
145+
railties (>= 6.1)
142146
drb (2.2.3)
143147
encoded_ids (1.1.0)
144148
hashid-rails (~> 1.0)
@@ -164,13 +168,6 @@ GEM
164168
net-http (~> 0.5)
165169
faraday-retry (2.4.0)
166170
faraday (~> 2.0)
167-
ffi (1.17.4-aarch64-linux-gnu)
168-
ffi (1.17.4-aarch64-linux-musl)
169-
ffi (1.17.4-arm-linux-gnu)
170-
ffi (1.17.4-arm-linux-musl)
171-
ffi (1.17.4-arm64-darwin)
172-
ffi (1.17.4-x86_64-linux-gnu)
173-
ffi (1.17.4-x86_64-linux-musl)
174171
flipper (1.4.2)
175172
concurrent-ruby (< 2)
176173
flipper-active_record (1.4.2)
@@ -228,7 +225,6 @@ GEM
228225
logger
229226
ostruct
230227
ice_cube (0.17.0)
231-
image_processing (2.0.2)
232228
importmap-rails (2.2.3)
233229
actionpack (>= 6.0.0)
234230
activesupport (>= 6.0.0)
@@ -502,9 +498,6 @@ GEM
502498
rubocop-performance (>= 1.24)
503499
rubocop-rails (>= 2.30)
504500
ruby-progressbar (1.13.0)
505-
ruby-vips (2.3.0)
506-
ffi (~> 1.12)
507-
logger
508501
rubyzip (3.3.0)
509502
safely_block (1.0.0)
510503
sanitize (7.0.0)
@@ -613,6 +606,7 @@ DEPENDENCIES
613606
console1984
614607
debug
615608
devise (~> 5.0)
609+
dotenv-rails
616610
encoded_ids
617611
factory_bot_rails
618612
faker
@@ -627,7 +621,6 @@ DEPENDENCIES
627621
htmlentities
628622
icalendar
629623
ice_cube
630-
image_processing (~> 2.0)
631624
importmap-rails
632625
jbuilder
633626
jwt
@@ -649,7 +642,6 @@ DEPENDENCIES
649642
rails (~> 8.1.3)
650643
rspec-rails
651644
rubocop-rails-omakase
652-
ruby-vips
653645
selenium-webdriver
654646
shoulda-matchers
655647
solid_cable
@@ -702,6 +694,8 @@ CHECKSUMS
702694
declarative (0.0.20) sha256=8021dd6cb17ab2b61233c56903d3f5a259c5cf43c80ff332d447d395b17d9ff9
703695
devise (5.0.4) sha256=d605f2b85854e74e56ee789e2d398702bc2d06e6bcd894717a670a3199c74cc1
704696
diff-lcs (1.6.2) sha256=9ae0d2cba7d4df3075fe8cd8602a8604993efc0dfa934cff568969efb1909962
697+
dotenv (3.2.0) sha256=e375b83121ea7ca4ce20f214740076129ab8514cd81378161f11c03853fe619d
698+
dotenv-rails (3.2.0) sha256=657e25554ba622ffc95d8c4f1670286510f47f2edda9f68293c3f661b303beab
705699
drb (2.2.3) sha256=0b00d6fdb50995fe4a45dea13663493c841112e4068656854646f418fda13373
706700
encoded_ids (1.1.0) sha256=5ecfc66a50688c76fc249b9f8e0537f00372ab06f33cdf182dd8d8905b3933f1
707701
erb (6.0.4) sha256=38e3803694be357fe2bfe312487c74beaf9fb4e5beb3e22498952fe1645b95d9
@@ -714,13 +708,6 @@ CHECKSUMS
714708
faraday-follow_redirects (0.5.0) sha256=5cde93c894b30943a5d2b93c2fe9284216a6b756f7af406a1e55f211d97d10ad
715709
faraday-net_http (3.4.4) sha256=0e78af151747ed1b00f33e25973b4bc220d7f16c00c39676817c8b12331eb588
716710
faraday-retry (2.4.0) sha256=7b79c48fb7e56526faf247b12d94a680071ff40c9fda7cf1ec1549439ad11ebe
717-
ffi (1.17.4-aarch64-linux-gnu) sha256=b208f06f91ffd8f5e1193da3cae3d2ccfc27fc36fba577baf698d26d91c080df
718-
ffi (1.17.4-aarch64-linux-musl) sha256=9286b7a615f2676245283aef0a0a3b475ae3aae2bb5448baace630bb77b91f39
719-
ffi (1.17.4-arm-linux-gnu) sha256=d6dbddf7cb77bf955411af5f187a65b8cd378cb003c15c05697f5feee1cb1564
720-
ffi (1.17.4-arm-linux-musl) sha256=9d4838ded0465bef6e2426935f6bcc93134b6616785a84ffd2a3d82bc3cf6f95
721-
ffi (1.17.4-arm64-darwin) sha256=19071aaf1419251b0a46852abf960e77330a3b334d13a4ab51d58b31a937001b
722-
ffi (1.17.4-x86_64-linux-gnu) sha256=9d3db14c2eae074b382fa9c083fe95aec6e0a1451da249eab096c34002bc752d
723-
ffi (1.17.4-x86_64-linux-musl) sha256=3fdf9888483de005f8ef8d1cf2d3b20d86626af206cbf780f6a6a12439a9c49e
724711
flipper (1.4.2) sha256=dca7d65b5ec660b525b6c599e727219ac4994073c855b41b6656b2d91a9cb304
725712
flipper-active_record (1.4.2) sha256=ab70aeb78a44d59c690b5538fc269b08d1c2918abb720fe82832ac77fb1dfcd1
726713
flipper-active_support_cache_store (1.4.2) sha256=474e4a558f791032af317592b2b27a4ff2ee663bc49627b8aec64ce7e79c9522
@@ -739,7 +726,6 @@ CHECKSUMS
739726
i18n (1.14.8) sha256=285778639134865c5e0f6269e0b818256017e8cde89993fdfcbfb64d088824a5
740727
icalendar (2.12.3) sha256=37dea76c36f5b21dd745bcd3cb53e7bacfbb4ad0a8d9c2a1c0aa9d39af83c850
741728
ice_cube (0.17.0) sha256=32deb45dda4b4acc53505c2f581f6d32b5afc04d29b9004769944a0df5a5fcbe
742-
image_processing (2.0.2) sha256=d0cf990f862d64efb1a14916044bf4b5bb2bccc7e235022413cde46019799cfa
743729
importmap-rails (2.2.3) sha256=7101be2a4dc97cf1558fb8f573a718404c5f6bcfe94f304bf1f39e444feeb16a
744730
io-console (0.8.2) sha256=d6e3ae7a7cc7574f4b8893b4fca2162e57a825b223a177b7afa236c5ef9814cc
745731
irb (1.18.0) sha256=de9454a0703a54704b9811a5ef31a60c86949fbf4013fcf244fabc7c775248e3
@@ -841,7 +827,6 @@ CHECKSUMS
841827
rubocop-rails (2.35.2) sha256=088865be9675922a5c8f13c00055a71ab768ea5eed211437cffd2a8b46b64ac2
842828
rubocop-rails-omakase (1.1.0) sha256=2af73ac8ee5852de2919abbd2618af9c15c19b512c4cfc1f9a5d3b6ef009109d
843829
ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33
844-
ruby-vips (2.3.0) sha256=e685ec02c13969912debbd98019e50492e12989282da5f37d05f5471442f5374
845830
rubyzip (3.3.0) sha256=a372fc67892a4f8c0bc8ec906b720353d8e48807a64b2e63adf99b1e3583a034
846831
safely_block (1.0.0) sha256=bea80e084e620adeada62fd98cf461bbb9888d40dc0f06d337df9d01e1a658e5
847832
sanitize (7.0.0) sha256=269d1b9d7326e69307723af5643ec032ff86ad616e72a3b36d301ac75a273984

bin/codespace-setup

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
cp .env.example .env
3+
4+
set -euo pipefail
5+
6+
cd "$(dirname "$0")/.."
7+
8+
PG_BIN_DIR="/usr/lib/postgresql/16/bin"
9+
export PATH="$PG_BIN_DIR:$PATH"
10+
11+
export POSTGRES_HOST="127.0.0.1"
12+
export POSTGRES_PORT="5432"
13+
export POSTGRES_USER="postgres"
14+
export POSTGRES_PASSWORD="postgres"
15+
export POSTGRES_DATABASE="calendar_development"
16+
export POSTGRES_TEST_DATABASE="calendar_test"
17+
18+
if ! command -v initdb >/dev/null 2>&1 || ! command -v pg_ctl >/dev/null 2>&1 || ! command -v psql >/dev/null 2>&1; then
19+
sudo apt-get update
20+
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql postgresql-contrib
21+
fi
22+
23+
PGDATA="$PWD/.postgres-data"
24+
PGSOCKET="$PWD/.postgres-socket"
25+
PGPORT="$POSTGRES_PORT"
26+
27+
mkdir -p "$PGSOCKET"
28+
29+
sudo service postgresql stop >/dev/null 2>&1 || true
30+
31+
if [[ ! -f "$PGDATA/PG_VERSION" ]]; then
32+
rm -rf "$PGDATA"
33+
initdb -D "$PGDATA" --auth-local=trust --auth-host=trust >/dev/null
34+
fi
35+
36+
pg_ctl -D "$PGDATA" stop >/dev/null 2>&1 || true
37+
pg_ctl -D "$PGDATA" -l "$PGDATA/logfile" -o "-k $PGSOCKET -p $PGPORT -c listen_addresses='$POSTGRES_HOST'" start >/dev/null
38+
39+
export PGHOST="$PGSOCKET"
40+
export PGPORT="$PGPORT"
41+
42+
if ! psql -d postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname = 'postgres'" | grep -q 1; then
43+
createuser --superuser --login --createdb postgres
44+
fi
45+
46+
psql -d postgres -tAc "ALTER ROLE postgres WITH SUPERUSER CREATEDB LOGIN PASSWORD 'postgres'" >/dev/null 2>&1 || true
47+
48+
psql -d postgres -tAc "ALTER DATABASE calendar_development OWNER TO postgres" >/dev/null 2>&1 || true
49+
psql -d postgres -tAc "ALTER DATABASE calendar_test OWNER TO postgres" >/dev/null 2>&1 || true
50+
51+
bundle check || bundle install
52+
53+
createdb -O postgres calendar_development 2>/dev/null || true
54+
createdb -O postgres calendar_test 2>/dev/null || true
55+
56+
bin/rails db:prepare
57+
bin/rails log:clear tmp:clear

config/database.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,20 @@ default: &default
1919
# https://guides.rubyonrails.org/configuring.html#database-pooling
2020
max_connections: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
2121

22-
2322
development:
2423
<<: *default
25-
database: calendar_development
24+
database: <%= ENV.fetch("POSTGRES_DATABASE", "calendar_development") %>
25+
host: <%= ENV.fetch("POSTGRES_HOST") %>
26+
port: <%= ENV.fetch("POSTGRES_PORT") %>
2627

2728
# The specified database role being used to connect to PostgreSQL.
2829
# To create additional roles in PostgreSQL see `$ createuser --help`.
2930
# When left blank, PostgreSQL will use the default role. This is
3031
# the same name as the operating system user running Rails.
31-
#username: calendar
32+
username: <%= ENV.fetch("POSTGRES_USER") %>
3233

3334
# The password associated with the PostgreSQL role (username).
34-
#password:
35+
password: <%= ENV.fetch("POSTGRES_PASSWORD") %>
3536

3637
# Connect on a TCP socket. Omitted by default since the client uses a
3738
# domain socket that doesn't need configuration. Windows does not have
@@ -56,7 +57,11 @@ development:
5657
# Do not set this db to the same as development or production.
5758
test:
5859
<<: *default
59-
database: calendar_test
60+
database: <%= ENV.fetch("POSTGRES_TEST_DATABASE", "calendar_test") %>
61+
host: <%= ENV.fetch("POSTGRES_HOST") %>
62+
port: <%= ENV.fetch("POSTGRES_PORT") %>
63+
username: <%= ENV.fetch("POSTGRES_USER") %>
64+
password: <%= ENV.fetch("POSTGRES_PASSWORD") %>
6065

6166
# As with config/credentials.yml, you never want to store sensitive information,
6267
# like your database password, in your source code. If your source code is

0 commit comments

Comments
 (0)