Skip to content

Commit 817497f

Browse files
committed
moar fixes for initial experience
1 parent 6bf50b4 commit 817497f

5 files changed

Lines changed: 91 additions & 22 deletions

File tree

README.md

Lines changed: 77 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ Intercode is a web application that:
1313

1414
Intercode 2 was a ground-up rewrite of Intercode, making it more robust, more flexible, and more modern. Starting at version 3.0.0, we've used [semantic versioning](https://semver.org/) for our releases.
1515

16-
# Overall Architecture
16+
## Overall Architecture
1717

1818
- **Backend**: Ruby on Rails application exposing a GraphQL API and an OpenID Connect-enabled OAuth2 server
1919
- **Frontend**: React and Apollo-based single-page JavaScript app
2020
- **Database engine**: PostgreSQL
2121
- **Background queue system**: Amazon SQS + Shoryuken (this might change in the future)
2222
- **Production infrastructure**: For [New England Interactive Literature](http://interactiveliterature.org)'s installation of Intercode, we're hosting it on [Fly](https://fly.io).
2323

24-
# Getting Started with Developing Intercode
24+
## Getting Started with Developing Intercode
2525

2626
- Intercode in development mode uses `intercode.test` as its cookie domain. If you use `localhost` to visit the site, that will mysteriously fail. I'm going to try to make the site detect the wrong domain and redirect you, but for now, please just use the `intercode.test` domain name.
2727
- We used to support a Docker Compose-based development workflow, but this has been deprecated. Please run Rails locally using the instructions below.
2828

29-
## Developer Setup with local Rails
29+
### Developer Setup with local Rails
3030

3131
This is the classic Rails development setup, and should work for Mac and Linux users. Windows users should use WSL.
3232

33-
### Dev tooling setup using mise
33+
#### Dev tooling setup using mise
3434

3535
In this tutorial, we're going to set up [mise-en-place](https://mise.jdx.dev) to manage the versions of Ruby and Node.js used to run Intercode. This will be a globally-installed tool on your system, so if you don't want to do it this way, know that there are other options such as [rbenv](https://github.com/sstephenson/rbenv#readme).
3636

@@ -58,12 +58,12 @@ mise settings ruby.compile=false
5858

5959
(The last one isn't strictly necessary but it should save a lot of time on the installation.)
6060

61-
### Setting up other dependencies
61+
#### Setting up other dependencies
6262

6363
On Linux and WSL, you'll need to have a few packages installed before setting up Intercode. For Debian and Ubuntu, this command should do it:
6464

6565
```sh
66-
sudo apt install git postgresql libmariadb-dev libvips zlib1g-dev libffi-dev libssl-dev libyaml-dev
66+
sudo apt install build-essential git postgresql libmariadb-dev libvips zlib1g-dev libffi-dev libssl-dev libyaml-dev
6767
```
6868

6969
On macOS, you should have [Homebrew](https://brew.sh/) installed. Homebrew will also guide you through installing the Xcode command line tools. Once that's done, run this:
@@ -94,7 +94,7 @@ psql postgres
9494

9595
This should let you into Postgres, this time as your local user account.
9696

97-
### Setting up Intercode
97+
#### Setting up Intercode
9898

9999
First, clone this repository:
100100

@@ -123,6 +123,47 @@ corepack enable
123123
yarn install
124124
```
125125

126+
#### Setting up the database
127+
128+
In theory, it should be possible to set up your local database using this command:
129+
130+
```sh
131+
bin/rails db:create db:migrate db:seed
132+
```
133+
134+
There are a few things that can go wrong here. Let's go through some common types of errors and how you can fix them:
135+
136+
<details>
137+
138+
<summary>`PG::ConnectionBad: connection to server at "::1", port 5432 failed: fe_sendauth: no password supplied (PG::ConnectionBad)`</summary>
139+
140+
If you're seeing something like this, you probably need to force Rails to connect to the database server using a UNIX socket as opposed to trying to connect via localhost TCP port 5432. To do this, we'll need to change the `DATABASE_URL` environment variables. Start by copying these lines from `.env.development` into `.env.development.local`:
141+
142+
```text
143+
DEVELOPMENT_DATABASE_URL=postgresql://localhost/intercode_development
144+
TEST_DATABASE_URL=postgresql://localhost/intercode_test
145+
```
146+
147+
Then, add the path to the UNIX socket as a `?host=` parameter at the end of both URLs. On Debian, the path to the socket is `/var/run/postgresql`, so these lines would become:
148+
149+
```text
150+
DEVELOPMENT_DATABASE_URL=postgresql://localhost/intercode_development?host=/var/run/postgresql
151+
TEST_DATABASE_URL=postgresql://localhost/intercode_test?host=/var/run/postgresql
152+
```
153+
154+
</details>
155+
156+
<details>
157+
158+
<summary>`psql:/home/debian/intercode/db/structure.sql:4: ERROR: unrecognized configuration parameter "transaction_timeout"`</summary>
159+
160+
If you're seeing something like this, you're probably running an older version of PostgreSQL than the one Intercode supports. We tend to track new PostgreSQL releases pretty closely, so you probably
161+
need the latest version available.
162+
163+
</details>
164+
165+
#### Setting up weird web serving nonsense
166+
126167
Intercode uses a somewhat unfortunate custom setup for local HTTP. Because some features require HTTPS, we generate a self-signed CA and certificate. In addition, Intercode expects to have different domain names for each convention it hosts, so we set up \*.intercode.test as a private fake DNS namespace for the local copy of Intercode to use.
127168

128169
First, let's generate the self-signed certificates:
@@ -136,18 +177,23 @@ On macOS, the above command will prompt for your password and install the CA in
136177

137178
Now, let's set up the private DNS namespace. The setup for this differs somewhat between different operating systems:
138179

139-
#### macOS
180+
<details>
181+
<summary>macOS</summary>
140182

141183
On macOS, create a file called `/etc/resolver/intercode.test` with the following contents:
142184

143-
```
185+
```text
144186
domain intercode.test
145187
nameserver 127.0.0.1
146188
```
147189

148190
To test that this is working, try running `ping randomname.intercode.test`. It should start pinging your local machine on 127.0.0.1.
149191

150-
#### Linux
192+
</details>
193+
194+
<details>
195+
196+
<summary>Linux</summary>
151197

152198
On Linux, there's no built-in way to do wildcard domain resolution like there is with macOS's resolver. But, we can use dnsmasq as a DNS resolver proxy and configure it to resolve \*.intercode.test to 127.0.0.1. First, install dnsmasq:
153199

@@ -157,20 +203,20 @@ sudo apt install dnsmasq
157203

158204
Then create a file called `/etc/dnsmasq.d/dnsmasq-intercode.conf` with the following contents:
159205

160-
```
206+
```text
161207
address=/intercode.test/127.0.0.1
162208
```
163209

164210
Now we need to get dnsmasq to play nice with systemd, which at least in Debian's setup, it won't do by default. First, edit `/etc/dnsmasq.conf` and add these lines:
165211

166-
```
212+
```text
167213
listen-address=127.0.0.2
168214
bind-interfaces
169215
```
170216

171217
This will make dnsmasq listen on 127.0.0.2, which won't conflict with systemd-resolved. We also need to get it to stop trying to listen on 127.0.0.1. To do that, edit `/etc/default/dnsmasq` and find the commented-out line that says `DNSMASQ_EXCEPT="lo"`. Uncomment it:
172218

173-
```
219+
```text
174220
DNSMASQ_EXCEPT="lo"
175221
```
176222

@@ -182,7 +228,7 @@ sudo systemctl restart dnsmasq
182228

183229
Once that's done, edit `/etc/systemd/resolved.conf` and find the commented-out line that begins with `DNS=`. Change it to say:
184230

185-
```
231+
```text
186232
DNS=127.0.0.2
187233
```
188234

@@ -194,7 +240,20 @@ sudo systemctl restart systemd-resolved.service
194240

195241
To test that this is working, try running `ping randomname.intercode.test`. It should start pinging your local machine on 127.0.0.1.
196242

197-
### Starting Intercode for the first time
243+
</details>
244+
245+
<details>
246+
<summary>Windows</summary>
247+
248+
On Windows, there's no built-in way to do wildcard domain resolution like there is with macOS's resolver. But, we can use a DNS resolver proxy such as [Acrylic](https://mayakron.altervista.org/support/acrylic/Home.htm) and configure it to resolve \*.intercode.test to 127.0.0.1.
249+
250+
I have not personally tried this, but if someone does and would like to contribute instructions to this README, I would be forever grateful!
251+
252+
<3, Nat
253+
254+
</details>
255+
256+
#### Starting Intercode for the first time
198257

199258
You'll need two terminals (or two terminal tabs) for this. In the first, start up the Rails backend server:
200259

@@ -236,17 +295,17 @@ If you want to test how the app runs in production, but using your local develop
236295
4. Run something like the following command, changing the asset host as necessary for your setup: `docker run -it -p 5051:3000 -e DATABASE_URL=postgresql://postgres@docker.for.mac.localhost/intercode_development -e RAILS_LOG_TO_STDOUT=true -e ASSETS_HOST=//intercont.intercode.test:5050 -e RAILS_SERVE_STATIC_FILES=true local-intercode-production bin/rails`
237296
5. Visit <https://some-convention-domain.intercode.test:5050>, probably using Firefox (it seems to deal better than Chrome with self-signed certificates these days).
238297

239-
# Contacting us
298+
## Contacting us
240299

241300
To contact the Intercode project team, you can:
242301

243302
- [File an issue or feature request here](https://github.com/neinteractiveliterature/intercode/issues)
244303
- [Email Nat Budin](mailto:natbudin@gmail.com).
245304

246-
# Code of Conduct
305+
## Code of Conduct
247306

248307
Participants in the Intercode project are expected to follow the Contributor Covenant. For details, [see CODE_OF_CONDUCT.md](https://github.com/neinteractiveliterature/intercode/blob/main/CODE_OF_CONDUCT.md).
249308

250-
# License
309+
## License
251310

252311
Intercode is released under the terms and conditions of the MIT license. Please see the LICENSE file for the full legalese.

app/models/root_site.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
# rubocop:enable Layout/LineLength, Lint/RedundantCopDisableDirective
2424

2525
class RootSite < ApplicationRecord
26-
belongs_to :root_page, class_name: "Page"
27-
belongs_to :default_layout, class_name: "CmsLayout"
26+
belongs_to :root_page, class_name: "Page", optional: true
27+
belongs_to :default_layout, class_name: "CmsLayout", optional: true
2828

2929
def self.instance
3030
RootSite.first

app/services/cms_content_loaders/cms_files.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ def storage_adapter
77
end
88

99
def create_item(_identifier, attrs)
10-
File.open(attrs[:path], 'rb') do |file|
10+
File.open(attrs[:path], "rb") do |file|
1111
cms_parent.cms_files.create!(file: { io: file, filename: File.basename(attrs[:path]) })
1212
end
1313
end
14+
15+
def existing_content_identifiers
16+
@existing_content_identifiers ||=
17+
Set.new(
18+
storage_adapter.cms_parent_association.joins(file_attachment: :blob).pluck(active_storage_blobs: "filename")
19+
)
20+
end
1421
end

db/seeds.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
#
66
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
77
# Mayor.create(name: 'Emanuel', city: cities.first)
8+
9+
LoadCmsContentSetService.new(convention: nil, content_set_name: "root_site").call!
10+
RootSite.instance.update!(site_name: "Root site")

db/structure.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2708,7 +2708,7 @@ CREATE TABLE public.signups (
27082708
counted boolean,
27092709
requested_bucket_key character varying,
27102710
expires_at timestamp without time zone,
2711-
CONSTRAINT bucket_key_null_for_non_slot_occupying_states CHECK (((bucket_key IS NULL) OR ((state)::text = ANY ((ARRAY['confirmed'::character varying, 'ticket_purchase_hold'::character varying])::text[]))))
2711+
CONSTRAINT bucket_key_null_for_non_slot_occupying_states CHECK (((bucket_key IS NULL) OR ((state)::text = ANY (ARRAY[('confirmed'::character varying)::text, ('ticket_purchase_hold'::character varying)::text]))))
27122712
);
27132713

27142714

0 commit comments

Comments
 (0)