Skip to content

enable local development #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions deploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
"dst": "/var/www/html/cc-test/.htaccess",
"add-header-comment": false
},
"// service worker",
{
"type": "move",
"src": "site/sw.js",
"dst": "/var/www/html/cc-test/sw.js",
"add-header-comment": true
},
"// web sources",
{
"type": "move",
Expand All @@ -36,7 +29,7 @@
"type": "move",
"src": "site/css/",
"dst": "/var/www/html/cc-test/css/",
"match": "^.*\\.(css|php)$",
"match": "^.*\\.(php)$",
"add-header-comment": true
},
{
Expand Down
16 changes: 16 additions & 0 deletions dev/docker/database/epicast/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# start with the `delphi_database` image
FROM delphi_database

# create the `epicast2` database
ENV MYSQL_DATABASE epicast2

# create the `epi` user account with a development-only password
ENV MYSQL_USER user
ENV MYSQL_PASSWORD pass

# provide DDL which will create empty tables at container startup
# note that files are executed in order of filename alphabetically, so here
# destination files are named such that table definitions are executed prior to
# data insertions
COPY repos/delphi/www-epicast/src/ddl/epicast2.sql /docker-entrypoint-initdb.d/0_epicast2.sql
COPY repos/delphi/www-epicast/src/ddl/development_data.sql /docker-entrypoint-initdb.d/1_development_data.sql
27 changes: 27 additions & 0 deletions dev/docker/database/epicast/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# `delphi_database_epicast`

This image extends Delphi's database by:

- adding the `epi` user account
- adding the `epicast2` database
- creating and minimally populating tables in `epicast2`

To start a container from this image, run:

```bash
docker run --rm -p 13306:3306 \
--network delphi-net --name delphi_database_epicast \
delphi_database_epicast
```

For debugging purposes, you can interactively connect to the database inside
the container using a `mysql` client (either installed locally or supplied via
a docker image) like this:

```bash
mysql --user=user --password=pass --port 13306 --host 127.0.0.1 epicast2
```

Note that using host `localhost` may fail on some platforms as mysql will
attempt, and fail, to use a Unix socket. Using `127.0.0.1`, which implies
TCP/IP, works instead.
27 changes: 27 additions & 0 deletions dev/docker/web/epicast/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# start with the `delphi_web` image
FROM delphi_web

# enable mod_rewrite, aka RewriteEngine
RUN a2enmod rewrite

# enable mod_headers
RUN a2enmod headers

# create an empty htpasswd file
RUN touch /var/www/passwords

# deploy the Epicast website (see `www-epicast/deploy.json`)
# deploy files in an order that tries to take advantage of build caching

COPY repos/delphi/www-epicast/site/images/* /var/www/html/images/
COPY repos/delphi/www-epicast/site/images/flags/* /var/www/html/images/flags/
COPY repos/delphi/www-epicast/site/data/* /var/www/html/data/

COPY repos/delphi/www-epicast/site/css/* /var/www/html/css/
COPY repos/delphi/www-epicast/site/js/*.js /var/www/html/js/
COPY repos/delphi/www-epicast/site/js/us-map /var/www/html/js/us-map
COPY repos/delphi/www-epicast/site/common/* /var/www/html/common/
COPY repos/delphi/www-epicast/site/*.php /var/www/html/

# point to the local development database (overwrites `common/settings.php`)
COPY repos/delphi/www-epicast/dev/docker/web/epicast/assets/settings.php /var/www/html/common/
24 changes: 24 additions & 0 deletions dev/docker/web/epicast/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# `delphi_web_epicast`

This image starts with Delphi's web server and adds the sources necessary for
hosting the Epicast website. It further extends Delphi's web server by:

- enabling the `mod_rewrite` extension
- enabling the `mod_headers` extension
- creating an empty `htpasswd` file

This image includes the file
[`settings.php`](assets/settings.php), which points to a local
container running the
[`delphi_database_epicast` image](../../database/epicast/README.md).

To start a container from this image, run:

```bash
docker run --rm -p 10080:80 \
--network delphi-net --name delphi_web_epicast \
delphi_web_epicast
```

You should be able to login and interact with the website (e.g. submitting
predictions) by visiting `http://localhost:10080/` in a web browser.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to make this work for a pandemic setup where, e.g., my development machine is on campus and I'm shelling into it from home? Are we talking X forwarding or is there a way to expose this address outside localhost?

Copy link
Contributor Author

@dfarrow0 dfarrow0 Apr 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh interesting, that's a good use-case. no need to X-forward. you should be able to use a reverse ssh tunnel to forward localhost:10080 on your at-home machine to localhost:10080 on your at-work machine.

from your at-home machine, this command should work:

ssh -N -L localhost:10080:localhost:10080 your-username@at-work-machine

This works by listening on port 10080 at-home and tunneling connections to port 10080 at-work. (The first localhost:10080 is where to listen at-home, the second localhost:10080 is where to connect at-work.)

This is probably something that should go in the guide. Do you mind letting me know if this works for you?

edit: fix terrible typo, this should be a forward tunnel, not reverse

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and to be clear, after the ssh command above, you can then open http://localhost:10080/ on your at-home machine, and you should see your "local" (at-work) instance of the website.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the db and web server running in docker on my work machine, and I can load the site in lynx from there. Alas, the ssh tunnel fails:

$ ssh -N -R localhost:10080:localhost:10080 <me>@<work>
<me>@<work>'s password: 
Warning: remote port forwarding failed for listen port 10080
^C$ ssh -N -R 127.0.0.1:10080:127.0.0.1:10080 <me>@<work>
<me>@<work>'s password: 
Warning: remote port forwarding failed for listen port 10080

--which seems weird; I'm not a tunneling pro but I've done something like this before. I'll have more time to debug tomorrow morning.

Copy link
Contributor Author

@dfarrow0 dfarrow0 Apr 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh my bad. this should be a forward tunnel, not reverse. just need to swap out -R with -L as in:

ssh -N -L 127.0.0.1:10080:127.0.0.1:10080 your-username@at-work-machine

(replaced localhost with 127.0.0.1 to be extra safe)

15 changes: 15 additions & 0 deletions dev/docker/web/epicast/assets/settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/* Settings and secrets for local development of the Epicast website. */

$dbHost = 'delphi_database_epicast';
$dbPort = 3306;
$dbUser = 'user';
$dbPass = 'pass';
$dbName = 'epicast2';

$epicastAdmin = array(
'name' => 'Delphi Developer',
'email' => 'fake_email_address',
);
?>
5 changes: 3 additions & 2 deletions site/.htaccess
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
RewriteEngine On

## Resrtict access to known users ##
## Restrict access to known users or docker development ##
AuthType Basic
AuthName "Restricted Site: Crowdcast"
AuthBasicProvider file
AuthUserFile /var/www/passwords
Require user cctest
## Resrtict access to known users ##
Require ip 172.16.0.0/12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be 127.16.0.0/12?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for taking a close look! that's a great question.

172 is correct in this case (but wow that is similar to 127...)

172.16.0.0/12 is one of the private IPv4 address ranges, which happens to be the range that Docker uses for internal networking.

The idea here is that we either want a valid user or someone connecting from a local private network, particularly Docker's network.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah -- the commit message says 127. probably muscle memory :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oof, definitely muscle memory. glad i typo'd the commit message and not the htaccess file 😄

## Restrict access to known users or docker development ##

## Compress Files ##
<IfModule mod_deflate.c>
Expand Down
Loading