-
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 #28 from wearefuturegov/feature/docker-package
Feature/docker package
- Loading branch information
Showing
51 changed files
with
5,104 additions
and
2,407 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
version: "3.7" | ||
services: | ||
mongo: | ||
image: mongo:6 | ||
ports: | ||
- 27018:27017 | ||
volumes: | ||
- mongo-volume:/data/db | ||
- ./setup-mongodb.js:/docker-entrypoint-initdb.d/mongo-init.js:ro | ||
environment: | ||
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME:-admin} | ||
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD:-password} | ||
MONGO_INITDB_USERNAME: ${MONGO_INITDB_USERNAME:-outpost} | ||
MONGO_INITDB_PASSWORD: ${MONGO_INITDB_PASSWORD:-password} | ||
MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE:-outpost_api_development} | ||
networks: | ||
- internal_network | ||
|
||
volumes: | ||
mongo-volume: |
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,35 @@ | ||
db = db.getSiblingDB( | ||
process.env.MONGO_INITDB_DATABASE || "outpost_api_development" | ||
) | ||
|
||
db.createUser({ | ||
user: process.env.MONGO_INITDB_USERNAME || "outpost", | ||
pwd: process.env.MONGO_INITDB_PASSWORD || "password", | ||
roles: [ | ||
{ | ||
role: "readWrite", | ||
db: process.env.MONGO_INITDB_DATABASE || "outpost_api_development", | ||
}, | ||
], | ||
}) | ||
|
||
db.createCollection("indexed_services") | ||
|
||
db.indexed_services.createIndex( | ||
{ | ||
name: "text", | ||
description: "text", | ||
}, | ||
{ | ||
weights: { | ||
name: 5, | ||
description: 1, | ||
}, | ||
} | ||
) | ||
db.indexed_services.createIndex({ | ||
"locations.geometry": "2dsphere", | ||
}) | ||
db.indexed_services.createIndex({ | ||
"taxonomies.slug": 1, | ||
}) |
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 |
---|---|---|
@@ -1,13 +1,34 @@ | ||
# git | ||
.git | ||
.dockerignore | ||
.gitattributes | ||
.gitignore | ||
.github | ||
|
||
# env | ||
.env | ||
.env.* | ||
|
||
# node | ||
node_modules | ||
|
||
# misc | ||
.DS_Store | ||
*.swp | ||
*~ | ||
|
||
# logs | ||
log/* | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.yarn-integrity | ||
|
||
# Added in case image is built locally without fresh checkout | ||
.idea | ||
.vscode | ||
node_modules/ | ||
bundle/ | ||
tmp/ | ||
environment/ | ||
docker-compose* | ||
Dockerfile | ||
.ruby-lsp | ||
coverage | ||
|
||
# heroku | ||
Procfile | ||
makefile | ||
.DS_Store |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 pre-builds the dev-base image and pushes it to the GitHub Container Registry (GHCR) | ||
|
||
name: Deploy outpost api image to github container registry | ||
|
||
on: | ||
push: | ||
branches: [develop, staging, production] | ||
|
||
jobs: | ||
push-outpost-api-image: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Checkout GitHub Action" | ||
uses: actions/checkout@main | ||
|
||
- name: "Login to GitHub Container Registry" | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{github.actor}} | ||
password: ${{secrets.GITHUB_TOKEN}} | ||
|
||
- name: Set Docker Image Tag | ||
id: vars | ||
run: | | ||
BRANCH_NAME=${GITHUB_REF#refs/heads/} | ||
if [[ "$BRANCH_NAME" == "develop" ]]; then | ||
echo "::set-output name=tag::development" | ||
elif [[ "$BRANCH_NAME" == "staging" ]]; then | ||
echo "::set-output name=tag::staging" | ||
elif [[ "$BRANCH_NAME" == "production" ]]; then | ||
echo "::set-output name=tag::latest" | ||
fi | ||
- name: Build and push outpost api docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
tags: ghcr.io/wearefuturegov/outpost-api-service:${{ steps.vars.outputs.tag }} | ||
file: Dockerfile.production | ||
platforms: ${{ matrix.platforms }} | ||
push: true | ||
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=Outpost API Service image | ||
labels: org.opencontainers.image.source=https://github.com/wearefuturegov/outpost-api-service |
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,23 @@ | ||
name: Run tests | ||
on: push | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/Iron | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Run tests | ||
run: npm run test | ||
|
||
- name: Upload coverage reports to Codecov | ||
uses: codecov/[email protected] | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
slug: wearefuturegov/outpost-api-service |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
node_modules | ||
.env | ||
/environment/artifacts | ||
.DS_Store | ||
.DS_Store | ||
coverage | ||
logs |
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 |
---|---|---|
@@ -1 +1 @@ | ||
v16.18.0 | ||
lts/Iron |
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 |
---|---|---|
@@ -1,27 +1,32 @@ | ||
# using docker image layers to save waiting for things to rebuild all the time | ||
ARG NODE_ENV=development | ||
|
||
# base_image > build_frontend > (development | production) | ||
# ---------------------------------------------------------------- | ||
FROM node:iron-alpine as build_frontend | ||
ARG NODE_ENV | ||
ENV NODE_ENV $NODE_ENV | ||
|
||
FROM node:16-alpine3.17 as base_image | ||
|
||
|
||
# copy node files and install | ||
FROM base_image as build_frontend | ||
COPY ./package.json ./tmp/package.json | ||
COPY ./package-lock.json ./tmp/package-lock.json | ||
RUN cd /tmp && \ | ||
npm i | ||
|
||
WORKDIR /tmp | ||
|
||
RUN if [ "${NODE_ENV}" = "development" ] || [ -z "${NODE_ENV}" ]; then \ | ||
npm install; fi | ||
RUN if [ "${NODE_ENV}" = "production" ]; then \ | ||
npm ci && npm cache clean --force; fi | ||
|
||
WORKDIR /app | ||
|
||
# build and install all the things for the development env | ||
FROM build_frontend as development | ||
COPY --from=build_frontend ./tmp ./app | ||
EXPOSE 3001 | ||
CMD ["npm", "run", "dev" ] | ||
# ---------------------------------------------------------------- | ||
FROM build_frontend | ||
ARG NODE_ENV | ||
ENV NODE_ENV $NODE_ENV | ||
|
||
COPY --from=build_frontend /tmp/package.json ./package.json | ||
COPY --from=build_frontend /tmp/package-lock.json ./package-lock.json | ||
COPY --from=build_frontend /tmp/node_modules ./node_modules | ||
|
||
|
||
FROM build_frontend as production | ||
COPY --from=build_frontend ./tmp ./ | ||
COPY . /app | ||
EXPOSE 3001 | ||
CMD ["npm", "run", "start" ] | ||
EXPOSE 3000 | ||
ENTRYPOINT ["npm", "run"] | ||
CMD ["dev"] |
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,36 @@ | ||
ARG NODE_ENV=production | ||
ARG FORCE_SSL=true | ||
|
||
# ---------------------------------------------------------------- | ||
FROM node:iron-alpine as build_frontend | ||
ARG NODE_ENV | ||
ARG FORCE_SSL | ||
ENV NODE_ENV $NODE_ENV | ||
RUN adduser -D outpost-user | ||
|
||
COPY ./package.json ./tmp/package.json | ||
COPY ./package-lock.json ./tmp/package-lock.json | ||
|
||
WORKDIR /tmp | ||
|
||
RUN if [ "${NODE_ENV}" = "development" ] || [ -z "${NODE_ENV}" ]; then \ | ||
npm install; fi | ||
RUN if [ "${NODE_ENV}" = "production" ]; then \ | ||
npm ci --omit=dev && npm cache clean --force; fi | ||
|
||
WORKDIR /app | ||
|
||
# ---------------------------------------------------------------- | ||
FROM build_frontend | ||
ARG NODE_ENV | ||
ARG FORCE_SSL | ||
ENV NODE_ENV $NODE_ENV | ||
ENV FORCE_SSL $FORCE_SSL | ||
|
||
COPY --from=build_frontend --chown=outpost-user:outpost-user /tmp/node_modules /app/node_modules | ||
COPY . /app | ||
|
||
USER outpost-user | ||
EXPOSE 3000 | ||
ENTRYPOINT ["npm", "run"] | ||
CMD ["start"] |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# TODO | ||
|
||
- [ ] Automate tests with docker and github actions | ||
- [x] Automate tests with docker and github actions | ||
- [ ] Automatic linter on commit and PR's | ||
- [ ] An option to push some dummy data to the API | ||
- [x] An option to push some dummy data to the API | ||
- [ ] Add support for csv export https://developers.openreferraluk.org/API-Guidance/ |
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,64 @@ | ||
{ | ||
"results": [ | ||
{ | ||
"address_components": [ | ||
{ | ||
"long_name": "London", | ||
"short_name": "London", | ||
"types": ["locality", "political"] | ||
}, | ||
{ | ||
"long_name": "London", | ||
"short_name": "London", | ||
"types": ["postal_town"] | ||
}, | ||
{ | ||
"long_name": "Greater London", | ||
"short_name": "Greater London", | ||
"types": ["administrative_area_level_2", "political"] | ||
}, | ||
{ | ||
"long_name": "England", | ||
"short_name": "England", | ||
"types": ["administrative_area_level_1", "political"] | ||
}, | ||
{ | ||
"long_name": "United Kingdom", | ||
"short_name": "GB", | ||
"types": ["country", "political"] | ||
} | ||
], | ||
"formatted_address": "London, UK", | ||
"geometry": { | ||
"bounds": { | ||
"northeast": { | ||
"lat": 51.6723432, | ||
"lng": 0.148271 | ||
}, | ||
"southwest": { | ||
"lat": 51.38494009999999, | ||
"lng": -0.3514683 | ||
} | ||
}, | ||
"location": { | ||
"lat": 51.5072178, | ||
"lng": -0.1275862 | ||
}, | ||
"location_type": "APPROXIMATE", | ||
"viewport": { | ||
"northeast": { | ||
"lat": 51.6723432, | ||
"lng": 0.148271 | ||
}, | ||
"southwest": { | ||
"lat": 51.38494009999999, | ||
"lng": -0.3514683 | ||
} | ||
} | ||
}, | ||
"place_id": "ChIJdd4hrwug2EcRmSrV3Vo6llI", | ||
"types": ["locality", "political"] | ||
} | ||
], | ||
"status": "OK" | ||
} |
Oops, something went wrong.