-
Notifications
You must be signed in to change notification settings - Fork 9
186 lines (159 loc) · 6.86 KB
/
test-in-herokuish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# @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]
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:
test-in-herokuish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- name: "Set up internal DB URIs"
run: |
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: "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: "Setup mongo"
run: |
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
# options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
- name: "Login to GitHub Container Registry"
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
- 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: ghcr.io/wearefuturegov/outpost:test
file: Dockerfile.test
load: true
# push: true
build-args: |
NODE_OPTIONS=--openssl-legacy-provider
RAILS_ENV=test
NODE_ENV=development
# - name: Test
# run: |
# docker run --rm outpost:test
- name: Run the image and tests
run: |
docker run --rm --name test_container \
--network $test_network_name \
-p 3000:3000 \
-e RAILS_ENV=test \
-e NODE_ENV=development \
-e RAILS_SERVE_STATIC_FILES=true \
-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 OFSTED_FEED_API_ENDPOINT=https://test-ofsted-feed.stub \
outpost:test
# docker exec test_container /exec bin/bundle exec rspec
# docker exec temp_container /bin/herokuish procfile exec bin/bundle exec rails assets:precompile
# @TODO fix static files not generating in this image
# name: Run tests in herokuish
# # on: [push]
# jobs:
# build:
# 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
# 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 "."
# # - 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: Run the tests in the docker container
# env:
# RAILS_SERVE_STATIC_FILES: true
# run: |
# docker run --rm --name outpost_test \
# --network host \
# -e RAILS_SERVE_STATIC_FILES=true \
# -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