Skip to content
This repository was archived by the owner on Oct 5, 2024. It is now read-only.

Commit 374eff9

Browse files
authored
Merge pull request #444 from spwoodcock/build/multi-stage-dockerfiles
Optimise dockerfiles, fix ci, release images
2 parents cdec730 + 06c131d commit 374eff9

13 files changed

+398
-101
lines changed

.dockerignore

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Ignore everything
2+
**
3+
4+
# Allow files and directories
5+
6+
# Underpass
7+
!src
8+
!config
9+
!setup
10+
!docker/bzip2.pc
11+
!autogen.sh
12+
!configure.ac
13+
!Makefile.am
14+
!m4
15+
!dist
16+
!docs
17+
!ABOUT-NLS
18+
!config.rpath
19+
!docker/ci-entrypoint.sh
20+
21+
# API
22+
!python

.github/workflows/docs.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ on:
66
- docs/**
77
- mkdocs.yml
88
branches:
9-
- master
9+
- master
10+
1011
permissions:
1112
contents: write
13+
1214
jobs:
1315
deploy:
1416
runs-on: ubuntu-latest

.github/workflows/release_img.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: 🔧 Build Release Image
2+
3+
on:
4+
release:
5+
types: [published]
6+
# Allow manual trigger
7+
workflow_dispatch:
8+
9+
jobs:
10+
underpass-build:
11+
uses: hotosm/gh-workflows/.github/workflows/[email protected]
12+
with:
13+
dockerfile: docker/underpass.dockerfile
14+
build_target: prod
15+
image_name: ghcr.io/${{ github.repository }}
16+
17+
api-build:
18+
uses: hotosm/gh-workflows/.github/workflows/[email protected]
19+
with:
20+
dockerfile: docker/underpass-api.dockerfile
21+
build_target: prod
22+
image_name: ghcr.io/${{ github.repository }}/api
23+
24+
ui-build:
25+
uses: hotosm/gh-workflows/.github/workflows/[email protected]
26+
with:
27+
dockerfile: docker/underpass-ui.dockerfile
28+
build_target: prod
29+
image_name: ghcr.io/${{ github.repository }}/ui

.github/workflows/tests.yml

+16-18
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
1-
name: 🧪 Build and test
1+
name: 🧪 Build and Test
22

33
on:
44
push:
55
branches:
66
- master
7+
pull_request:
8+
branches:
9+
- master
710
paths:
811
- src/**
912
- .github/workflows/**
1013
- docker/**
14+
# Allow manual trigger
15+
workflow_dispatch:
1116

1217
jobs:
13-
build:
14-
runs-on: ubuntu-latest
15-
steps:
16-
- name: Checkout
17-
uses: actions/checkout@v2
18-
# Relies on the master branch built docker image for build-deps
19-
- name: Start Docker Compose & build
20-
run: cd docker && docker-compose up -d underpass
21-
# Build and run tests
22-
- name: Build and run tests
23-
run: |
24-
docker-compose -f docker-compose.yml exec -T underpass sh -c "cd /code/build && make check -j `nproc`"
25-
exit_code=$?
26-
if [ $exit_code -ne 0 ]; then
27-
echo "Test failed with exit code $exit_code"
28-
exit $exit_code
29-
fi
18+
build-and-test:
19+
uses: hotosm/gh-workflows/.github/workflows/[email protected]
20+
with:
21+
image_name: ghcr.io/${{ github.repository }}
22+
build_dockerfile: docker/underpass.dockerfile
23+
compose_service: underpass
24+
compose_command: echo "Tests complete."
25+
# TODO update postgis image to use github repo var ${{ vars.POSTGIS_TAG }}
26+
cache_extra_imgs: |
27+
"docker.io/postgis/postgis:15-3.3-alpine"
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"pull_request": {
3+
"head": {
4+
"ref": "feat/some-new-thing"
5+
},
6+
"base": {
7+
"ref": "master"
8+
}
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"base_ref ": "master",
3+
"ref": "refs/heads/master"
4+
}

.github/workflows/tests/test_ci.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
########################################
6+
# Note: run this from the repo root.
7+
########################################
8+
9+
# Tests
10+
act pull_request -W .github/workflows/tests.yml \
11+
-e .github/workflows/tests/pr_payload.json
12+
13+
# Docs
14+
act push -W .github/workflows/docs.yml \
15+
-e .github/workflows/tests/pr_payload.json
16+
17+
# Release
18+
act release -W .github/workflows/release_img.yml \
19+
-e .github/workflows/tests/push_payload.json

ci/ci_local.sh

+4-16
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,12 @@ cd ${TEMP_DIR}
1919
make distclean -j `nproc` || true
2020
make clean -j `nproc` || true
2121

22-
DOCKER_DIR="${TEMP_DIR}"
23-
DOCKER_COMPOSE_FILE="${DOCKER_DIR}/docker-compose.yml"
24-
DOCKER_BASE_COMMAND="docker-compose -f ${DOCKER_COMPOSE_FILE}"
22+
# Run CI
23+
APP_VERSION=ci docker compose run underpass --exit-code-from=underpass
2524

26-
# Run the composition
27-
${DOCKER_BASE_COMMAND} up -d
25+
# Shut down containers
26+
APP_VERSION=ci docker compose down
2827

29-
# Build Underpass Library and Binaries
30-
${DOCKER_BASE_COMMAND} exec -T underpass sh -c "cd /code && git clean -fx && git clean -f -d && ./autogen.sh && (rm -rf build || true) && mkdir build && cd build && ../configure --enable-shared && make -j `nproc`"
31-
32-
# Build and Run Underpass Tests - broken: alway succeeds
33-
${DOCKER_BASE_COMMAND} exec -T underpass sh -c "cd /code/build/src/testsuite/libunderpass.all && make check -j `nproc`"
34-
35-
# Comment the cleanup lines below or exit here if you want to run additional
36-
# tests from a console in the temp container, for instance with:
37-
${DOCKER_BASE_COMMAND} exec underpass bash
38-
39-
${DOCKER_BASE_COMMAND} down
4028
echo "Remove temporary folder ${TEMP_DIR}"
4129
sudo rm -rf ${TEMP_DIR}
4230

docker-compose.yml

+26-11
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ version: "3"
2222
services:
2323
# Database
2424
postgis:
25-
image: postgis/postgis:15-3.3
26-
# image: arm64v8/postgres:15.3-alpine3.18
25+
image: postgis/postgis:${POSTGIS_TAG:-15-3.3-alpine}
2726
container_name: "underpass_postgis"
2827
ports:
29-
- "5439:5432"
28+
- "${DB_PORT:-5439}:5432"
3029
environment:
3130
- POSTGRES_DB=underpass
3231
- POSTGRES_USER=underpass
@@ -44,44 +43,60 @@ services:
4443

4544
# Underpass
4645
underpass:
46+
image: "ghcr.io/hotosm/underpass:${APP_VERSION:-debug}"
4747
container_name: "underpass"
4848
build:
4949
context: .
5050
dockerfile: docker/underpass.dockerfile
51+
target: debug
52+
args:
53+
APP_VERSION: ${APP_VERSION:-debug}
54+
depends_on: [postgis]
5155
environment:
5256
- REPLICATOR_UNDERPASS_DB_URL=underpass:underpass@postgis/underpass
5357
command: tail -f /dev/null
5458
volumes:
5559
- ./replication:/code/build/replication
56-
# - ./:/code
60+
# - ./:/code
5761
networks:
5862
internal:
5963

6064
# Underpass API
61-
underpass-api:
65+
api:
66+
image: "ghcr.io/hotosm/underpass/api:${APP_VERSION:-debug}"
6267
container_name: "underpass_api"
6368
build:
6469
context: .
6570
dockerfile: docker/underpass-api.dockerfile
66-
# volumes:
67-
# - ./python:/code/api
71+
target: debug
72+
args:
73+
APP_VERSION: ${APP_VERSION:-debug}
74+
depends_on: [underpass]
75+
volumes:
76+
- ./python:/code
6877
ports:
69-
- "8000:8000"
78+
- "${API_PORT:-8000}:8000"
7079
networks:
7180
internal:
7281
environment:
7382
- UNDERPASS_API_DB=postgresql://underpass:underpass@postgis/underpass
7483

7584
# Underpass UI
76-
underpass-ui:
85+
ui:
86+
image: "ghcr.io/hotosm/underpass/ui:${APP_VERSION:-debug}"
7787
container_name: "underpass_ui"
7888
build:
7989
context: .
8090
dockerfile: docker/underpass-ui.dockerfile
91+
target: debug
92+
args:
93+
APP_VERSION: ${APP_VERSION:-debug}
94+
# # Mount underpass-ui repo
8195
# volumes:
82-
# - js:/code
96+
# - ../underpass-ui/src:/code/src
97+
# - ../underpass-ui/playground:/code/playground
8398
ports:
84-
- "5000:5000"
99+
- "${UI_PORT:-8080}:5000"
85100
networks:
86101
internal:
87102

docker/ci-entrypoint.sh

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
yellow_echo() {
6+
local message="$1"
7+
local separator="--------------------------------------------------------"
8+
local sep_length=${#separator}
9+
local pad_length=$(( (sep_length - ${#message}) / 2 ))
10+
local pad=""
11+
12+
for ((i=0; i<pad_length; i++)); do
13+
pad="$pad "
14+
done
15+
16+
echo ""
17+
echo -e "\e[0;33m$separator\e[0m"
18+
echo -e "\e[0;33m$pad$message$pad\e[0m"
19+
echo -e "\e[0;33m$separator\e[0m"
20+
echo ""
21+
}
22+
23+
# Generate makefiles
24+
yellow_echo "Generating Makefiles"
25+
./autogen.sh
26+
27+
echo
28+
echo "Entering 'build' directory"
29+
cd build
30+
31+
# Test build works
32+
yellow_echo "Building Underpass"
33+
../configure
34+
make -j $(nproc)
35+
make install
36+
37+
# Run tests
38+
yellow_echo "Running Tests"
39+
cd /code/build/src/testsuite/libunderpass.all
40+
make check -j `nproc`

0 commit comments

Comments
 (0)