Skip to content

Commit 9446e57

Browse files
authored
fix: changes for hokusai dev/test. (#2889)
* fix: replace docker-compose extends with jinja template. * fix: replace extends with jinja template, in test.yml. * fix: re-arrange Docker build steps, to reduce delay in hokusai dev start. * fix: build.yml can be removed now extends is not used. * fix: update README for hokusai dev * feat: use host network mode for docker compose services. * fix: with development.yml using host network mode, mongo/es URL's can be taken from .env. update README accordingly. * fix: change .env.example ELASTICSEARCH_URL to localhost.
1 parent e5859af commit 9446e57

File tree

6 files changed

+63
-52
lines changed

6 files changed

+63
-52
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SESSION_SECRET=p0s1tr0n
99
ELASTICSEARCH_PORT=9200
1010

1111
# Local development only for the below; refers to the key in docker-compose.yml
12-
ELASTICSEARCH_URL=http://elasticsearch:9200
12+
ELASTICSEARCH_URL=http://localhost:9200
1313
MONGOHQ_URL=mongodb://localhost:27017/positron
1414

1515
##

Dockerfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ RUN apk add --no-cache --quiet \
1818
COPY package.json yarn.lock ./
1919
RUN yarn install --frozen-lockfile && yarn cache clean
2020

21-
# Copy application code
22-
COPY . ./
21+
# Update file/directory permissions
22+
RUN chown -R deploy:deploy ./
2323

24-
# Ensure COMMIT_HASH is present
25-
RUN test -n "$COMMIT_HASH" && \
26-
echo $COMMIT_HASH > COMMIT_HASH.txt && \
27-
# Update file/directory permissions
28-
chown -R deploy:deploy ./
24+
# Copy application code
25+
COPY --chown=deploy:deploy . ./
2926

3027
# Switch to less-privileged user
3128
USER deploy
3229

30+
# Ensure COMMIT_HASH is present
31+
# Run this step as late as possible b/c it busts docker cache.
32+
RUN test -n "$COMMIT_HASH" && \
33+
echo $COMMIT_HASH > COMMIT_HASH.txt
34+
3335
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
3436
CMD ["yarn", "start"]

README.md

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,35 @@
2222

2323
[![Build Status](https://circleci.com/gh/artsy/positron/tree/master.svg?style=svg)](https://circleci.com/gh/artsy/positron/tree/master) [![codecov](https://codecov.io/gh/artsy/positron/branch/master/graph/badge.svg)](https://codecov.io/gh/artsy/positron)
2424

25-
## Set-Up
25+
## Setup
2626

27-
### Via Hokusai
28-
29-
- Set up [Hokusai](https://github.com/artsy/README/blob/master/playbooks/hokusai.md#quickstart)
30-
- `git clone git@github.com:<your username>/positron.git && cd positron`
31-
- `COMMIT_HASH=$(git rev-parse --short HEAD) hokusai dev start`
32-
33-
This starts a new Docker Compose stack that boots MongoDB, ElasticSearch and Positron. Changes made to source-code are _not_ automatically reloaded. To shut down, press `ctrl+c` or execute `hokusai dev stop`.
34-
35-
### Manually
36-
37-
- Install [NVM](https://github.com/creationix/nvm)
38-
- Install Node 12
39-
40-
```
41-
nvm install 12
42-
nvm alias default 12
43-
```
27+
### Preparation
4428

4529
- Fork Positron to your Github account in the Github UI.
30+
4631
- Clone your repo locally (substitute your Github username).
4732

4833
```
4934
git clone git@github.com:craigspaeth/positron.git && cd positron
5035
```
36+
- Setup [Hokusai](https://github.com/artsy/README/blob/master/playbooks/hokusai.md#quickstart)
5137

5238
- Copy `.env.example` to `.env` in the root of the project and edit all `REPLACE` values with sensitive configuration obtained from `positron-staging`. Use the following command:
5339

5440
```
5541
hokusai staging env get | grep -E `cat .env.example | grep REPLACE | cut -f1 -d= | xargs | tr ' ' \|` | sed -e 's/:\ /=/g' | sed -e 's/ //g'
5642
```
5743

44+
### Installs (skip if you use hokusai dev, please see section below)
45+
46+
- Install [NVM](https://github.com/creationix/nvm)
47+
- Install Node 12
48+
49+
```
50+
nvm install 12
51+
nvm alias default 12
52+
```
53+
5854
- Install node modules
5955

6056
```
@@ -80,10 +76,15 @@ brew install elasticsearch
8076
brew services start elasticsearch
8177
```
8278

83-
- Create a dummy channel
84-
In order to write articles, you will need to be a member of a channel. If you are an Artsy dev, you will likely want to point your MONGOHQ_URL to the staging database. Because staging/production databases are protected on our VPC, it is required that you give user permissions to your AWS account and run the [Tunnelblick VPN](https://tunnelblick.net/) while connecting to the database. See details on [setting up a VPN connection here](https://github.com/artsy/infrastructure/blob/master/README.md#vpn).
79+
### Prepare database
80+
81+
#### Using staging database
82+
83+
In order to write articles, you will need to be a member of a channel. If you are an Artsy dev, you can point MONGOHQ_URL env to the staging database. Connecting to staging database requires VPN, please see details on [setting up a VPN connection here](https://github.com/artsy/infrastructure/blob/master/README.md#vpn).
84+
85+
#### Using a local database
8586

86-
If using a local database, use these steps to backfill required data:
87+
With MongoDB running locally, follow these steps to create a dummy channel:
8788

8889
1. Create a collection called `channels` in a `positron` db in your mongo database (You can use the mongo shell or a simple UI like Robomongo.)
8990
2. Add a document with the following fields:
@@ -96,23 +97,44 @@ brew services start elasticsearch
9697
}
9798
```
9899

99-
- Start the server
100+
If you are using Hokusai dev, start the stack as mentioned in subsequent section, edit the database as mentioned in this step, then restart the stack.
101+
102+
103+
### Start the server
104+
105+
#### Using Yarn
100106

101107
```
102108
yarn start
103109
```
104110

105-
- Positron should now be running at [http://localhost:3005/](http://localhost:3005/), open a browser and navigate to it. That will redirect you to staging, login as an Artsy administrator and it will redirect you to `http://localhost:3005` logged into Writer. If you are an Artsy Admin pointed to the staging database, you should see the default partner gallery channel (David Zwirner).
111+
#### Using Hokusai Dev
106112

107-
If you aren't an artsy admin you'll possibly get an Unauthorized page. You need to do one more mongo operation: edit the `users` collection and set your user's `channel_ids` to `[ ObjectId("<your_above_channel_id>") ]`. Once that's done you should be able to see the main writer interface.
113+
`COMMIT_HASH=$(git rev-parse --short HEAD) hokusai dev start`
114+
115+
This starts a new Docker Compose stack that boots MongoDB, ElasticSearch and Positron. Changes made to source-code are _not_ automatically reloaded. To shut down, press `ctrl+c` or execute `hokusai dev stop`.
108116

109-
- Run tests
117+
118+
Positron should now be running at [http://localhost:3005/](http://localhost:3005/), open a browser and navigate to it. That will redirect you to staging, login as an Artsy administrator and it will redirect you to `http://localhost:3005` logged into Writer.
119+
120+
If you are an Artsy Admin, you should see the default partner gallery channel (David Zwirner). If you aren't an artsy admin you'll possibly get an Unauthorized page. You need to do one more mongo operation: edit the `users` collection and set your user's `channel_ids` to `[ ObjectId("<your_above_channel_id>") ]`. Once that's done you should be able to see the main writer interface.
121+
122+
## Run tests
123+
124+
### Using Yarn
110125

111126
```
112127
yarn test
113128
```
114129

115-
- Make sure you have mongo running in the background or most tests will not work.
130+
Make sure you have mongo running in the background or most tests will not work.
131+
132+
### Using Hokusai
133+
134+
```
135+
hokusai test
136+
```
137+
116138

117139
## Debugging
118140

hokusai/development.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
11
version: "2"
22
services:
33
positron:
4+
{% include 'templates/docker-compose-service.yml.j2' %}
45
command: ["yarn", "dev"]
5-
extends:
6-
file: build.yml
7-
service: positron
8-
ports:
9-
- 3005:3005
10-
environment:
11-
- ELASTICSEARCH_URL=http://positron-elasticsearch:9200
12-
- MONGOHQ_URL=mongodb://positron-mongodb:27017/positron
136
env_file: ../.env
147
depends_on:
158
- positron-mongodb
169
- positron-elasticsearch
10+
network_mode: "host"
1711
positron-elasticsearch:
1812
image: docker.elastic.co/elasticsearch/elasticsearch:5.6.16
1913
environment:
2014
- discovery.type=single-node
2115
- xpack.security.enabled=false
2216
- bootstrap.memory_lock=true
2317
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
24-
ports:
25-
- "9200:9200"
18+
network_mode: "host"
2619
positron-mongodb:
2720
image: mongo:4.0
28-
ports:
29-
- "27017:27017"
3021
command: ["--storageEngine=mmapv1", "--quiet", "--nojournal"]
22+
network_mode: "host"

hokusai/build.yml renamed to hokusai/templates/docker-compose-service.yml.j2

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
version: "2"
2-
services:
3-
positron:
41
build:
52
context: ../
63
args:

hokusai/test.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ version: "2"
22
services:
33
positron:
44
command: ["yarn", "test"]
5-
extends:
6-
file: build.yml
7-
service: positron
5+
{% include 'templates/docker-compose-service.yml.j2' %}
86
environment:
97
- CI=true
108
- ELASTICSEARCH_URL=http://positron-elasticsearch:9200

0 commit comments

Comments
 (0)