docker-compose for functional testing

This commit is contained in:
Jamil Bou Kheir
2020-04-23 21:46:47 -07:00
parent a99a33fa7a
commit 674f608c47
9 changed files with 129 additions and 75 deletions

View File

@@ -1,19 +0,0 @@
name: Build
description: 'Build and push docker images.'
on:
push:
branches:
- master
jobs:
build-app-image:
runs-on: ubuntu:18.04
steps:
- uses: actions/checkout@v2
- name: Build Docker Image
run: |
docker build -t cloudfirellc/cloudfire:${GITHUB_SHA::8} .
- name: Push Docker Image
run: |
docker push cloudfirellc/cloudfire:latest

View File

@@ -1,8 +0,0 @@
name: Deploy
description: "Deploy images"
on:
release: created
jobs:

67
.github/workflows/main.yml vendored Normal file
View File

@@ -0,0 +1,67 @@
# Steps:
# 1. Unit/Integration Tests
# 2. Build and Push App Image
# 3. Functional Test
name: Test
description: "Unit, Integration, and Functional tests."
on:
- push
jobs:
# 1. Unit/Integration Test
unit-integration-test:
runs-on: ubuntu-18.04
env:
MIX_ENV: test
POSTGRES_HOST: localhost
services:
postgres:
image: postgres:12
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- name: Run Static Tests
uses: actions/setup-elixir@v1
with:
elixir-version: 1.10.2
otp-version: 22.3.2
- name: Install Dependencies
run: mix deps.get --only test
- name: Setup Database
run: |
mix ecto.create
mix ecto.migrate
- name: Run Tests
run: mix test
# 2. Build and Push App Image
build-app-image:
env:
TEST_IMAGE: docker.pkg.github.com/CloudFire-LLC/cloudfire-ce/cloudfire:${GITHUB_SHA::8}
runs-on: ubuntu:18.04
steps:
- uses: actions/checkout@v2
- name: Build Docker Image
run: docker build -t $TEST_IMAGE -f Dockerfile .
- name: Push Docker Image
run: docker push $TEST_IMAGE
# 3. Functional Test
docker-compose-up:
env:
TEST_IMAGE: docker.pkg.github.com/CloudFire-LLC/cloudfire-ce/cloudfire:${GITHUB_SHA::8}
runs-on: ubuntu:18.04
steps:
- uses: actions/checkout@v2
- name: Functional Test
run: |
docker-compose up -d -f docker-compose.yml -f docker-compose.test.yml
echo 'Tests completed!'

View File

@@ -1,41 +0,0 @@
# Unit test
name: CI
on:
- push
- pull_request
jobs:
unit-test:
runs-on: ubuntu-18.04
env:
MIX_ENV: test
POSTGRES_HOST: localhost
services:
postgres:
image: postgres:12
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- name: Run Static Tests
uses: actions/setup-elixir@v1
with:
elixir-version: 1.10.2
otp-version: 22.3.2
- name: Install Dependencies
run: mix deps.get --only test
- name: Setup Database
run: |
mix ecto.create
mix ecto.migrate
- name: Run Tests
run: mix test

View File

@@ -40,8 +40,9 @@ COPY $PHOENIX_DIR/lib $PHOENIX_DIR/lib
COPY apps/system_engine/lib ./apps/system_engine/
RUN mix compile
# Build release
RUN mix release bundled
# Build releases
RUN mix release cf_phx
RUN mix release system_engine
# The built application is now contained in _build/

5
docker-compose.dev.yml Normal file
View File

@@ -0,0 +1,5 @@
services:
cf-phx:
build: ./
system-engine:
build: ./

5
docker-compose.test.yml Normal file
View File

@@ -0,0 +1,5 @@
services:
cf-phx:
image: ${TEST_IMAGE}
system-engine:
image: ${TEST_IMAGE}

44
docker-compose.yml Normal file
View File

@@ -0,0 +1,44 @@
# The base docker-compose
version: "3.8"
services:
cf-phx:
command: /app/bin/cf_phx start
image: cloudfirellc/cloudfire:latest
environment:
DATABASE_URL: ecto://postgres:postgres@db/cloudfire
# !! WARNING !!
# Change this for production systems!
# !!!!!!!!!!!!!
SECRET_KEY_BASE: vw5YEoG6Pb7mCQEC41DjJXIB6v1/tOxO+3YLN+5k+PILkcFMN54g22KXZr6o65Bn
ports:
- 4000:4000
networks:
- cloudfire
system-engine:
command: /app/bin/system_engine start
image: cloudfirellc/cloudfire:latest
networks:
- cloudfire
db:
networks:
- cloudfire
image: postgres:12
volumes:
- pg-data:/var/lib/postgresql/data
environment:
# !! WARNING !!
# Change this for production systems!
# !!!!!!!!!!!!!
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
volumes:
pg-data:
networks:
cloudfire:

10
mix.exs
View File

@@ -8,11 +8,11 @@ defmodule CloudfireUmbrella.MixProject do
start_permanent: Mix.env() == :prod,
deps: deps(),
releases: [
bundled: [
applications: [
cf_phx: :permanent,
system_engine: :permanent
]
cf_phx: [
applications: [cf_phx: :permanent]
],
system_engine: [
applications: [system_engine: :permanent]
]
]
]