-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from wearefuturegov/develop
staging deployment
- Loading branch information
Showing
11 changed files
with
184 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# This action tests to make sure that the docker image can be built successfully on the specified platforms | ||
|
||
name: Test outpost-api-image docker build | ||
|
||
on: push | ||
|
||
jobs: | ||
test-docker-build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
platforms: ["linux/amd64", "linux/arm64", "linux/arm64/v8"] | ||
steps: | ||
- name: "Checkout GitHub Action" | ||
uses: actions/checkout@main | ||
|
||
- name: Set Docker Image Tag | ||
id: vars | ||
run: | | ||
BRANCH_NAME=${GITHUB_HEAD_REF#refs/heads/} | ||
if [[ "$BRANCH_NAME" == "develop" ]]; then | ||
echo "tag=development" >> $GITHUB_ENV | ||
elif [[ "$BRANCH_NAME" == "staging" ]]; then | ||
echo "tag=staging" >> $GITHUB_ENV | ||
elif [[ "$BRANCH_NAME" == "production" ]]; then | ||
echo "tag=latest" >> $GITHUB_ENV | ||
else | ||
echo "tag=default" >> $GITHUB_ENV | ||
fi | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Build Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
tags: outpost-api-service:${{ env.tag }} | ||
file: Dockerfile.production | ||
platforms: ${{ matrix.platforms }} | ||
push: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# This action tests to make sure that the docker image can be built successfully on the specified platforms | ||
|
||
name: Run tests in docker container | ||
|
||
on: push | ||
|
||
jobs: | ||
test-in-docker: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: "Checkout GitHub Action" | ||
uses: actions/checkout@main | ||
|
||
- name: "Create custom network" | ||
run: docker network create outpost-api-test-network | ||
|
||
- name: "Setup mongo" | ||
run: | | ||
docker run --rm -d -p 27017:27017 \ | ||
--name mongo \ | ||
-e MONGO_INITDB_ROOT_USERNAME=admin \ | ||
-e MONGO_INITDB_ROOT_PASSWORD=password \ | ||
-e MONGO_INITDB_USERNAME=outpost \ | ||
-e MONGO_INITDB_PASSWORD=password \ | ||
-e MONGO_INITDB_DATABASE=outpost_api_development \ | ||
-v $PWD/.docker/services/mongo/setup-mongodb.js:/docker-entrypoint-initdb.d/mongo-init.js:ro \ | ||
--network=outpost-api-test-network \ | ||
mongo:latest | ||
- name: Set Docker Image Tag | ||
id: vars | ||
run: | | ||
BRANCH_NAME=${GITHUB_HEAD_REF#refs/heads/} | ||
if [[ "$BRANCH_NAME" == "develop" ]]; then | ||
echo "tag=development" >> $GITHUB_ENV | ||
elif [[ "$BRANCH_NAME" == "staging" ]]; then | ||
echo "tag=staging" >> $GITHUB_ENV | ||
elif [[ "$BRANCH_NAME" == "production" ]]; then | ||
echo "tag=latest" >> $GITHUB_ENV | ||
else | ||
echo "tag=default" >> $GITHUB_ENV | ||
fi | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Build Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
tags: outpost-api-service:${{ env.tag }} | ||
file: Dockerfile.production | ||
push: false | ||
load: true | ||
build-args: | | ||
NODE_ENV=development | ||
FORCE_SSL=false | ||
- name: Run the image | ||
env: | ||
DB_URI: mongodb://outpost:password@mongo:27017/outpost_api_development | ||
run: | | ||
docker run --rm -d \ | ||
-e DEBUG_LEVEL=debug \ | ||
-e DB_URI=$DB_URI \ | ||
--name temp_container \ | ||
--network=outpost-api-test-network \ | ||
outpost-api-service:${{ env.tag }} | ||
docker exec temp_container npm run dummy-data | ||
docker exec temp_container npm run test | ||
docker stop temp_container |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,62 +34,37 @@ To run it on your machine you need Node.js, npm, nvm (https://github.com/nvm-sh/ | |
|
||
## 🧬 Configure Outpost API | ||
|
||
It expects a few environment variables. | ||
|
||
`DB_URI` | ||
|
||
- MongoDB connection URI | ||
|
||
`GOOGLE_API_KEY` | ||
|
||
- Used for geocoding `location=` parameters. | ||
- **Needs the geocoding API enabled.** | ||
|
||
Other environmental variables: | ||
|
||
`COMPOSE_PROJECT_NAME` | ||
|
||
- This is used to name the docker images and containers | ||
|
||
--- | ||
See [environmental variables](#environmental-variables) below. | ||
|
||
## 💻 Running it locally | ||
|
||
It is recommended to use docker but you can choose to run the project locally as well. | ||
|
||
```sh | ||
# get the code | ||
git clone [email protected]:wearefuturegov/outpost-api-service.git && cd outpost-api-service | ||
|
||
# make sure your using the correct node version | ||
nvm use | ||
|
||
# setup env and database variables | ||
# see setting up database below | ||
cp sample.env .env | ||
|
||
# Setup your database locally (see below) or start up a database using docker | ||
# NB this runs mongo on a non-standard port `27018` in case you have mongo already running, you can change it to `27017` if you would like to | ||
# connect with compass or mongosh with: mongodb://outpost:password@localhost:27018 | ||
docker compose up -d mongo | ||
|
||
# once its setup you can just use this to restart it | ||
docker start outpost-api-db | ||
|
||
# install dependencies | ||
npm install | ||
# setup | ||
docker compose up -d | ||
|
||
# run development mode | ||
npm run dev | ||
# if you need dummy data | ||
docker compose exec app npm run dummy-data | ||
|
||
# access the api | ||
open http://localhost:3001/api/v1/services | ||
|
||
# add some dummy data (if required) | ||
npm run dummy-data | ||
# access the mongodb | ||
# NB this runs mongo on a non-standard port `27018` in case you have mongo already running, you can change it to `27017` if you would like to | ||
mongo "mongodb://outpost:password@localhost:27018/outpost_api_development" | ||
|
||
# stop your database | ||
# stop the application at any time by running | ||
docker compose stop | ||
|
||
# delete your database image | ||
# remove the running containers by running | ||
docker compose down | ||
|
||
``` | ||
|
||
### Setting up database locally | ||
|
@@ -102,8 +77,6 @@ mongosh .docker/services/mongo/setup-mongodb.js | |
npm run prepare-indices | ||
``` | ||
|
||
or you can use the following commands to create your indices | ||
|
||
# 🧬 Configuration | ||
|
||
## Environmental Variables | ||
|
@@ -112,10 +85,13 @@ You can provide config with a `.env` file. Run `cp sample.env .env` to create a | |
|
||
The following environmental variables are required. | ||
|
||
| Variable | Description | Example | Required? | | ||
| ---------------- | ------------------ | -------------------------------------------------------------------- | --------- | | ||
| `DB_URI` | Mongo database url | `mongodb://outpost:password@localhost:27018/outpost_api_development` | Yes | | ||
| `GOOGLE_API_KEY` | Google API Key | `1234` | Yes | | ||
| Variable | Description | Example | Required? | | ||
| ---------------- | ------------------------------------------------------------------------- | -------------------------------------------------------------------- | --------- | | ||
| `DB_URI` | Mongo database url | `mongodb://outpost:password@localhost:27018/outpost_api_development` | Yes | | ||
| `GOOGLE_API_KEY` | Google API Key | `1234` | Yes | | ||
| `DEBUG_LEVEL` | Debug logging level options are: error, warn, info, http, debug | `debug` | No | | ||
| `FORCE_SSL` | Force SSL defaults to false unless this is set to true | true | No | | ||
| `HOST_PORT` | If running in docker set this to change the exposed port, default is 3000 | 3001 | No | | ||
|
||
# ✨ Features | ||
|
||
|
@@ -133,6 +109,8 @@ You will need to enable the `Geocode API`, no restrictions are needed. | |
|
||
It's suitable for 12-factor hosting like Heroku. It has a [Procfile](https://devcenter.heroku.com/articles/procfile) that will make sure the proper MongoDB indices are set up. | ||
|
||
Ensure you set `FORCE_SSL` to true. | ||
|
||
### Deploying using docker | ||
|
||
We also provide a Docker image if you would like to host the application in a container | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.