Skip to content

Commit

Permalink
Merge pull request #354 from wearefuturegov/develop
Browse files Browse the repository at this point in the history
Sr
  • Loading branch information
apricot13 authored Jun 24, 2024
2 parents 8f5565b + bf7031b commit 81a42b5
Show file tree
Hide file tree
Showing 38 changed files with 936 additions and 147,966 deletions.
3 changes: 2 additions & 1 deletion .docker/services/mongo/mongo.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
version: "3.7"
services:
mongo:
image: mongo:6
image: mongo:latest
platform: linux/arm64
ports:
- 27018:27017
volumes:
Expand Down
2 changes: 1 addition & 1 deletion .docker/services/mongo/setup-mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ db.indexed_services.createIndex(
}
);
db.indexed_services.createIndex({
"locations.geometry": "2dsphere",
"service_at_locations.location.geometry": "2dsphere",
});
db.indexed_services.createIndex({
"taxonomies.slug": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.7"
services:
outpost-api-service:
image: ghcr.io/wearefuturegov/outpost-api-service:latest
container_name: outpost-api-service
platform: linux/arm64
environment:
NODE_ENV: development
FORCE_SSL: false
Expand Down
32 changes: 0 additions & 32 deletions .github/workflows/outpost-image.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This action pre-builds the dev-base image and pushes it to the GitHub Container Registry (GHCR)

name: Deploy dev-base image to github container registry
name: Publish outpost dev-base image to github container registry

on:
push:
Expand All @@ -12,7 +12,7 @@ on:
- cron: "0 8 1 * *"

jobs:
push-dev-base-image:
publish-dev-base:
runs-on: ubuntu-latest
steps:
- name: "Checkout GitHub Action"
Expand All @@ -31,7 +31,6 @@ jobs:
context: .
tags: ghcr.io/wearefuturegov/outpost-dev-base
file: .docker/images/dev-base/Dockerfile
platforms: ${{ matrix.platforms }}
push: true
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=Outpost dev base image
labels: org.opencontainers.image.source=https://github.com/wearefuturegov/outpost
56 changes: 56 additions & 0 deletions .github/workflows/publish-outpost-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# This action pre-builds the dev-base image and pushes it to the GitHub Container Registry (GHCR)

name: Publish outpost image to github container registry

on:
push:
branches: [develop, staging, production]

# multi platform builds are disabled until we upgrade to a newer version of heroku stack
jobs:
push-outpost-image:
runs-on: ubuntu-latest
# strategy:
# matrix:
# platforms: ["linux/amd64"]
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 "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 and push outpost docker image
uses: docker/build-push-action@v5
with:
context: .
tags: ghcr.io/wearefuturegov/outpost:${{ env.tag }}
file: Dockerfile.production
# platforms: ${{ matrix.platforms }}
push: true
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=Outpost image
labels: org.opencontainers.image.source=https://github.com/wearefuturegov/outpost
38 changes: 38 additions & 0 deletions .github/workflows/test-docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This action tests to make sure that the docker image can be built successfully on the specified platforms

name: Test outpost image docker build

on: [push]

jobs:
test-docker-build:
runs-on: ubuntu-latest
strategy:
matrix:
platforms: ["linux/amd64"]
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: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
tags: outpost:${{ env.tag }}
file: Dockerfile.production
platforms: ${{ matrix.platforms }}
push: false
137 changes: 85 additions & 52 deletions .github/workflows/test-in-herokuish.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,101 @@
# @TODO fix static files not generating in this image
# RAILS_ENV: test
# NODE_ENV: development
# test_mongo_local_db_uri="mongodb://$(test_mongo_db_user):$(test_mongo_db_password)@localhost:$(test_mongo_port)/$(test_mongo_db_name)"
# test_postgres_local_db_uri="postgresql://$(test_postgres_db_user):$(test_postgres_db_password)@localhost:$(test_postgres_port)/$(test_postgres_db_name)"

name: Run tests in herokuish

# on: [push]
on: [push]

env:
test_network_name: outpost-test-network
test_mongo_container_name: outpost-test-mongo
test_mongo_init_db_user: admin
test_mongo_init_db_password: password
test_mongo_db_name: outpost_api_test
test_mongo_db_user: outpost
test_mongo_db_password: password
test_postgres_container_name: outpost-test-postgres
test_postgres_db_name: outpost_test
test_postgres_db_user: outpost
test_postgres_db_password: password
test_mongo_internal_db_uri: "mongodb://$test_mongo_db_user:$test_mongo_db_password@$test_mongo_container_name:27017/$test_mongo_db_name"
test_postgres_internal_db_uri: "postgresql://$test_postgres_db_user:$test_postgres_db_password@$test_postgres_container_name:5432/outpost?"

jobs:
build:
test-in-herokuish:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:13.7-alpine
env:
POSTGRES_USER: outpost
POSTGRES_PASSWORD: password
POSTGRES_DB: outpost_test
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
mongo:
image: mongo:6
env:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: password
ports:
- 27017:27017

steps:
- uses: actions/checkout@main

- name: Build the Docker test image
- name: "Set up internal DB URIs"
run: |
docker build \
--build-arg NODE_OPTIONS=--openssl-legacy-provider \
--build-arg NODE_ENV=development \
--build-arg RAILS_ENV=test \
-f "Dockerfile.test" \
-t outpost:test "."
echo "test_mongo_internal_db_uri=mongodb://${{ env.test_mongo_db_user }}:${{ env.test_mongo_db_password }}@${{ env.test_mongo_container_name }}:27017/${{ env.test_mongo_db_name }}" >> $GITHUB_ENV
echo "test_postgres_internal_db_uri=postgresql://${{ env.test_postgres_db_user }}:${{ env.test_postgres_db_password }}@${{ env.test_postgres_container_name }}:5432/${{ env.test_postgres_db_name }}" >> $GITHUB_ENV
# - name: Precompile assets
# run: |
# docker run --rm --name outpost_test \
# --entrypoint /build \
# --network host \
# -e GOOGLE_API_KEY=${{ secrets.GOOGLE_API_KEY }} \
# -e "DATABASE_URL=postgresql://outpost:password@localhost:5432/outpost?" \
# -e "DB_URI=mongodb://root:password@localhost:27017/outpost_development?authSource=admin" \
# -e OFSTED_FEED_API_ENDPOINT=https://test-ofsted-feed.stub \
# -e NODE_ENV=development \
# -e RAILS_ENV=test \
# -v .:/tmp/app \
# outpost:test /bin/herokuish procfile exec bin/bundle exec rails assets:precompile
- name: "Connection info"
run: |
echo $test_mongo_internal_db_uri
echo $test_postgres_internal_db_uri
- name: "Create custom network"
run: docker network create $test_network_name

- name: Run the tests in the docker container
env:
RAILS_SERVE_STATIC_FILES: true
- name: "Setup mongo"
run: |
docker run --rm --name outpost_test \
--network host \
docker run -d --name $test_mongo_container_name \
--network $test_network_name \
-p 27017:27017 \
-v $PWD/.docker/services/mongo/setup-mongodb.js:/docker-entrypoint-initdb.d/mongo-init.js:ro \
-e MONGO_INITDB_ROOT_USERNAME=$test_mongo_init_db_user \
-e MONGO_INITDB_ROOT_PASSWORD=$test_mongo_init_db_password \
-e MONGO_INITDB_USERNAME=$test_mongo_db_user \
-e MONGO_INITDB_PASSWORD=$test_mongo_db_password \
-e MONGO_INITDB_DATABASE=$test_mongo_db_name \
mongo:latest
- name: "Setup postgres"
run: |
docker run -d --name $test_postgres_container_name \
--network $test_network_name \
-p 5432:5432 \
-e POSTGRES_DB=$test_postgres_db_name \
-e POSTGRES_PASSWORD=$test_postgres_db_password \
-e POSTGRES_USER=$test_postgres_db_user \
postgres:13.7-alpine
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
tags: outpost:test
file: Dockerfile.test
load: true
# push: true
build-args: |
RACK_ENV=test
RAILS_ENV=test
NPM_CONFIG_PRODUCTION=false
NPM_CONFIG_LOGLEVEL=error
USE_YARN_CACHE=true
NODE_OPTIONS=--openssl-legacy-provider
NODE_VERBOSE=false
NODE_ENV=test
NODE_MODULES_CACHE=true
- name: Run the image and tests
run: |
docker run --rm --name test_container \
--network $test_network_name \
-p 3000:3000 \
-e RACK_ENV=test \
-e RAILS_ENV=test \
-e NODE_ENV=test \
-e RAILS_SERVE_STATIC_FILES=true \
-e SECRET_KEY_BASE=dummy \
-e DB_URI=$test_mongo_internal_db_uri \
-e DATABASE_URL=$test_postgres_internal_db_uri \
-e GOOGLE_API_KEY=${{ secrets.GOOGLE_API_KEY }} \
-e "DATABASE_URL=postgresql://outpost:password@localhost:5432/outpost?" \
-e "DB_URI=mongodb://root:password@localhost:27017/outpost_development?authSource=admin" \
-e OFSTED_FEED_API_ENDPOINT=https://test-ofsted-feed.stub \
-e NODE_ENV=development \
-e RAILS_ENV=test \
-v .:/tmp/app \
-e DATABASE_CLEANER_ALLOW_PRODUCTION=true \
outpost:test
Loading

0 comments on commit 81a42b5

Please sign in to comment.