Skip to content

Commit 2ac068e

Browse files
authored
Use docker compose for development (#1894)
* docker compose working * empty lines * env and docs * dockerfile * host breaks locally * cleanup instructions * update env vars and docs * extra space
1 parent fcca6a8 commit 2ac068e

File tree

13 files changed

+190
-52
lines changed

13 files changed

+190
-52
lines changed

.env.template

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Example environment configuration file: copy to `.env` (this is git-ignored) and fill in any additional values you need.
2+
3+
# ALGOLIA_APP_ID=
4+
# ALGOLIA_SEARCH_KEY=
5+
# ALGOLIA_WRITE_KEY=
6+
7+
DRUPAL_ROOT=https://live-mbta.pantheonsite.io
8+
OPEN_TRIP_PLANNER_URL=http://otp2-local.mbtace.com
9+
RECAPTCHA_PUBLIC_KEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
10+
RECAPTCHA_PRIVATE_KEY=6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe
11+
12+
# V3_API_KEY=
13+
V3_API_VERSION=2019-07-01
14+
V3_URL=https://api-dev.mbtace.com
15+
16+
# You can optionally set a Redis host and port.
17+
# The default host is 127.0.0.1
18+
# If you're using Docker Compose, the host is 10.0.0.11
19+
# The default port is 6379
20+
# If you're using Redis for local development, the port is 30001
21+
# REDIS_HOST=
22+
# REDIS_PORT=
23+
24+
# These credentials control access to resetting cache entries for the CMS.
25+
# You can set them to be whatever you want.
26+
# But, they'll need to match those on the Drupal side if you're doing CMS development.
27+
# BASIC_AUTH_USERNAME=
28+
# BASIC_AUTH_PASSWORD=

.envrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Loads the .env file that is used by Docker Compose.
2+
dotenv
3+
4+
# Gets AWS credentials from the AWS CLI configuration.
5+
$(aws configure export-credentials --format env)

.envrc.template

Lines changed: 0 additions & 41 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ erl_crash.dump
99
.ruby-version
1010
.vscode
1111
.elixir_ls
12-
.envrc
12+
.env
1313

1414
# Elastic Beanstalk Files
1515
.elasticbeanstalk/*

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
deploy/dotcom/Dockerfile
1+
deploy/dotcom/prod/Dockerfile

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Welcome to [Dotcom](https://www.notion.so/mbta-downtown-crossing/Dotcom-6aa7b0f0
124124
125125
1. Set up required environment variables:
126126
```
127-
cp .envrc.template .envrc
127+
cp .env.template .env
128128
```
129129
Then uncomment the `V3_API_KEY` line and fill it in with the key you obtained
130130
in the first step. If you have [direnv] installed (recommended), it will automatically load
@@ -138,10 +138,16 @@ For details on environment configuration, including optional variables, see
138138
139139
## Running the Server
140140
141-
You will need to have Redis running in cluster mode.
141+
The easiest way to develop MBTA dotcom is to use Docker Compose.
142+
143+
```
144+
docker compose -f deploy/dev.yml up -d
145+
```
146+
147+
This will set up Redis in cluster mode among other things.
148+
149+
If you choose not to use Docker Compose, you'll still have to run Redis cluster.
142150
The easiest way to get it running is to download and compile it.
143-
But, we plan to Dockerize all of our dependencies in the near future.
144-
Until then:
145151
146152
```
147153
cd $HOME
@@ -158,13 +164,13 @@ When you're done with it:
158164
```
159165
./utils/create-cluster/create-cluster stop
160166
cd $HOME
161-
rm 7.2.tar.gz
167+
rm 7.2.4.tar.gz
162168
rm -rf redis-7.2.4
163169
```
164170
165-
Start the server with `mix phx.server`
171+
Start the server with `iex -S mix phx.server`
166172
167-
Then, visit the site at http://localhost:4001/
173+
Then, visit the site at http://localhost:4001.
168174
169175
## Algolia
170176

config/runtime.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ if config_env() == :dev do
3636
config :dotcom, DotcomWeb.Endpoint,
3737
# Binding to loopback ipv4 address prevents access from other machines.
3838
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
39-
http: [ip: {127, 0, 0, 1}, port: port],
39+
http: [ip: {0, 0, 0, 0}, port: port],
4040
static_url: static_url
4141

4242
config :dotcom,

deploy/dev.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
version: "3"
2+
services:
3+
dotcom:
4+
build:
5+
context: ../
6+
dockerfile: ./deploy/dotcom/dev/Dockerfile
7+
env_file:
8+
- ../.env
9+
depends_on:
10+
- redis-cluster-init
11+
environment:
12+
- MIX_ENV=dev
13+
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
14+
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
15+
expose:
16+
- 4001
17+
ports:
18+
- 4001:4001
19+
- 8090:8090
20+
volumes:
21+
- ../:/app
22+
networks:
23+
redis_network:
24+
ipv4_address: 10.0.0.2
25+
monitor:
26+
build:
27+
context: ../
28+
dockerfile: ./deploy/monitor/Dockerfile
29+
env_file:
30+
- ../.env
31+
command: node /home/runner/integration/monitor/all-health-checks.js
32+
networks:
33+
redis_network:
34+
ipv4_address: 10.0.0.3
35+
redis-cluster-init:
36+
image: redis:7.2.4
37+
command: redis-cli --cluster create 10.0.0.11:6379 10.0.0.12:6379 10.0.0.13:6379 10.0.0.14:6379 10.0.0.15:6379 10.0.0.16:6379 --cluster-replicas 1 --cluster-yes
38+
depends_on:
39+
redis-1:
40+
condition: service_healthy
41+
redis-2:
42+
condition: service_healthy
43+
redis-3:
44+
condition: service_healthy
45+
redis-4:
46+
condition: service_healthy
47+
redis-5:
48+
condition: service_healthy
49+
redis-6:
50+
condition: service_healthy
51+
networks:
52+
redis_network:
53+
ipv4_address: 10.0.0.10
54+
redis-1: &redis
55+
build:
56+
context: ../
57+
dockerfile: ./deploy/redis/Dockerfile
58+
healthcheck:
59+
test: [ "CMD", "redis-cli", "PING"]
60+
timeout: 10s
61+
interval: 3s
62+
retries: 10
63+
environment:
64+
- CLUSTER_ANNOUNCE_IP=10.0.0.11
65+
networks:
66+
redis_network:
67+
ipv4_address: 10.0.0.11
68+
redis-2:
69+
<<: *redis
70+
environment:
71+
- CLUSTER_ANNOUNCE_IP=10.0.0.12
72+
networks:
73+
redis_network:
74+
ipv4_address: 10.0.0.12
75+
redis-3:
76+
<<: *redis
77+
environment:
78+
- CLUSTER_ANNOUNCE_IP=10.0.0.13
79+
networks:
80+
redis_network:
81+
ipv4_address: 10.0.0.13
82+
redis-4:
83+
<<: *redis
84+
environment:
85+
- CLUSTER_ANNOUNCE_IP=10.0.0.14
86+
networks:
87+
redis_network:
88+
ipv4_address: 10.0.0.14
89+
redis-5:
90+
<<: *redis
91+
environment:
92+
- CLUSTER_ANNOUNCE_IP=10.0.0.15
93+
networks:
94+
redis_network:
95+
ipv4_address: 10.0.0.15
96+
redis-6:
97+
<<: *redis
98+
environment:
99+
- CLUSTER_ANNOUNCE_IP=10.0.0.16
100+
networks:
101+
redis_network:
102+
ipv4_address: 10.0.0.16
103+
networks:
104+
redis_network:
105+
driver: bridge
106+
ipam:
107+
config:
108+
- subnet: 10.0.0.0/8
109+
gateway: 10.0.0.1

deploy/dotcom/dev/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM hexpm/elixir:1.16.1-erlang-26.2.2-debian-buster-20240130
2+
3+
RUN apt-get update && apt-get install -y curl git make build-essential inotify-tools
4+
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
5+
RUN apt-get install -y nodejs
6+
7+
WORKDIR /app
8+
9+
COPY mix.exs .
10+
COPY mix.lock .
11+
COPY package.json .
12+
COPY assets/package.json ./assets/package.json
13+
14+
RUN mix local.hex --force
15+
RUN mix local.rebar --force
16+
17+
CMD mix deps.get && npm install && npm run build && mix phx.digest && npm install --ignore-scripts && mix phx.server
File renamed without changes.

0 commit comments

Comments
 (0)