Skip to content

Commit

Permalink
Merge pull request #244 from WordPress/improv_just
Browse files Browse the repository at this point in the history
Organise and document `justfile`
  • Loading branch information
dhruvkb authored Sep 28, 2021
2 parents 29aa052 + c3c1d1d commit fbf3fbd
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Run API tests
working-directory: ./openverse_api
env:
PIPENV_DOTENV_LOCATION: ./.env.stencil
PIPENV_DOTENV_LOCATION: ./env.template
run: pipenv run test/run_test.sh
- name: Run analytics tests
working-directory: ./analytics
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This repository is primarily concerned with back end infrastructure like datasto
cd openverse-api/
```

3. From the monorepo root, bring up the Docker Compose system. Docker Compose will automatically read the necessary environment variables from `.env.docker` files from project directories.
3. From the monorepo root, bring up the Docker Compose system. Docker Compose will automatically read the necessary environment variables from `env.docker` files from project directories.
```bash
just up
```
Expand Down
10 changes: 5 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
ports:
- "5432:5432"
env_file:
- postgres/.env.docker
- postgres/env.docker
healthcheck:
test: "pg_isready -U deploy -d openledger"

Expand All @@ -22,7 +22,7 @@ services:
volumes:
- ./sample_data:/sample_data
env_file:
- postgres/.env.docker
- postgres/env.docker
healthcheck:
test: "pg_isready -U deploy -d openledger"

Expand Down Expand Up @@ -59,7 +59,7 @@ services:
- es
- cache
env_file:
- openverse_api/.env.docker
- openverse_api/env.docker
stdin_open: true
tty: true

Expand All @@ -80,7 +80,7 @@ services:
volumes:
- ./ingestion_server:/ingestion_server
env_file:
- ingestion_server/.env.docker
- ingestion_server/env.docker
stdin_open: true
tty: true

Expand All @@ -96,7 +96,7 @@ services:
volumes:
- ./ingestion_server:/ingestion_server
env_file:
- ingestion_server/.env.docker
- ingestion_server/env.docker
stdin_open: true
tty: true

Expand Down
2 changes: 1 addition & 1 deletion ingestion_server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ will be `"INGEST_UPSTREAM"`.

## Configuration

All configuration is performed through environment variables. See the `.env.stencil` file for a comprehensive list of all environment variables. The ones with sane defaults have been commented out.
All configuration is performed through environment variables. See the `env.template` file for a comprehensive list of all environment variables. The ones with sane defaults have been commented out.

Pipenv will automatically load `.env` files when running commands with `pipenv run`.

Expand Down
File renamed without changes.
File renamed without changes.
81 changes: 50 additions & 31 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,58 +1,77 @@
set dotenv-load := false

DOCKER_FILE := "-f docker-compose.yml"

# Show all available recipes
default:
@just --list --unsorted

install:
#! /usr/bin/env sh
cd openverse_api
pipenv install --dev
pipenv run pre-commit install

##########
# Docker #
##########

lint:
#! /usr/bin/env sh
cd openverse_api
pipenv run pre-commit run --all-files


env:
#! /usr/bin/env sh
cp openverse_api/.env.stencil openverse_api/.env
cp ingestion_server/.env.stencil ingestion_server/.env

DOCKER_FILE := "-f docker-compose.yml"

# Bring all Docker services up
up:
docker-compose {{ DOCKER_FILE }} up -d


# Take all Docker services down
down args="":
docker-compose {{ DOCKER_FILE }} down {{ args }}

# Show logs of all, or named, Docker services
logs services="":
docker-compose {{ DOCKER_FILE }} logs -f {{ services }}


########
# Init #
########

# Create .env files from stencils
env:
cp openverse_api/env.template openverse_api/.env
cp ingestion_server/env.template ingestion_server/.env

# Load sample data into the Docker Compose services
init: up
./load_sample_data.sh


# Make a test cURL request to the API
healthcheck:
curl "http://localhost:8000/v1/images/stats/"


test: up
docker-compose exec web ./test/run_test.sh
#######
# Dev #
#######

# Install Python dependencies in Pipenv environments
install:
cd openverse_api && pipenv install --dev
cd ingestion_server && pipenv install --dev

testlocal:
#! /usr/bin/env sh
cd openverse_api
pipenv run ./test/run_test.sh
# Setup pre-commit as a Git hook
precommit:
cd openverse_api && pipenv run pre-commit install

# Run pre-commit to lint and reformat all files
lint:
cd openverse_api && pipenv run pre-commit run --all-files


#######
# API #
#######

logs service="":
docker-compose {{ DOCKER_FILE }} logs -f {{ service }}
# Run API tests inside Docker
test: up
docker-compose exec web ./test/run_test.sh

# Run API tests locally
testlocal:
cd openverse_api && pipenv run ./test/run_test.sh

# Run Django administrative commands
dj args="":
#! /usr/bin/env sh
cd openverse_api
pipenv run python manage.py {{ args }}
cd openverse_api && pipenv run python manage.py {{ args }}
2 changes: 1 addition & 1 deletion openverse_api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ You can view the custom administration views at the `/admin/` endpoint. You can

## Configuration

All configuration is performed through environment variables. See the `.env.stencil` file for a comprehensive list of all environment variables. The ones with sane defaults have been commented out.
All configuration is performed through environment variables. See the `env.template` file for a comprehensive list of all environment variables. The ones with sane defaults have been commented out.

Pipenv will automatically load `.env` files when running commands with `pipenv run`.

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit fbf3fbd

Please sign in to comment.