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

Commit cdec730

Browse files
authored
Merge pull request #449 from hotosm/revert-447-feature/ci
Revert "Merge: Optimise dockerfiles, fix ci, release images"
2 parents a573a2b + c37e4aa commit cdec730

14 files changed

+103
-377
lines changed

.dockerignore

-22
This file was deleted.

.github/workflows/release_img.yml

-29
This file was deleted.

.github/workflows/tests.yml

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
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
107
paths:
118
- src/**
129
- .github/workflows/**
1310
- docker/**
1411

1512
jobs:
16-
build-and-test:
17-
uses: hotosm/gh-workflows/.github/workflows/[email protected]
18-
with:
19-
image_name: ghcr.io/${{ github.repository }}
20-
build_dockerfile: docker/underpass.dockerfile
21-
compose_service: underpass
22-
compose_command: echo "Tests complete."
23-
# TODO update postgis image to use github repo var ${{ vars.POSTGIS_TAG }}
24-
cache_extra_imgs: |
25-
"docker.io/postgis/postgis:15-3.3-alpine"
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

.github/workflows/tests/pr_payload.json

-10
This file was deleted.

.github/workflows/tests/push_payload.json

-4
This file was deleted.

.github/workflows/tests/test_ci.sh

-19
This file was deleted.

ci/ci_local.sh

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

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

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

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
2840
echo "Remove temporary folder ${TEMP_DIR}"
2941
sudo rm -rf ${TEMP_DIR}
3042

docker-compose.yml

+13-29
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ version: "3"
2222
services:
2323
# Database
2424
postgis:
25-
image: postgis/postgis:${POSTGIS_TAG:-15-3.3-alpine}
25+
image: postgis/postgis:15-3.3
26+
# image: arm64v8/postgres:15.3-alpine3.18
2627
container_name: "underpass_postgis"
2728
ports:
28-
- "${DB_PORT:-5439}:5432"
29+
- "5439:5432"
2930
environment:
3031
- POSTGRES_DB=underpass
3132
- POSTGRES_USER=underpass
@@ -43,61 +44,44 @@ services:
4344

4445
# Underpass
4546
underpass:
46-
image: "ghcr.io/hotosm/underpass:${APP_VERSION:-debug}"
47-
container_name: underpass
47+
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]
5551
environment:
5652
- REPLICATOR_UNDERPASS_DB_URL=underpass:underpass@postgis/underpass
5753
command: tail -f /dev/null
5854
volumes:
5955
- ./replication:/code/build/replication
60-
# # Mount code
6156
# - ./:/code
6257
networks:
6358
internal:
6459

6560
# Underpass API
66-
api:
67-
image: "ghcr.io/hotosm/underpass/api:${APP_VERSION:-debug}"
68-
container_name: underpass_api
61+
underpass-api:
62+
container_name: "underpass_api"
6963
build:
7064
context: .
7165
dockerfile: docker/underpass-api.dockerfile
72-
target: debug
73-
args:
74-
APP_VERSION: ${APP_VERSION:-debug}
75-
depends_on: [underpass]
76-
volumes:
77-
- ./python:/code
66+
# volumes:
67+
# - ./python:/code/api
7868
ports:
79-
- "${API_PORT:-8000}:8000"
69+
- "8000:8000"
8070
networks:
8171
internal:
8272
environment:
8373
- UNDERPASS_API_DB=postgresql://underpass:underpass@postgis/underpass
8474

8575
# Underpass UI
86-
ui:
87-
image: "ghcr.io/hotosm/underpass/ui:${APP_VERSION:-debug}"
88-
container_name: underpass_ui
76+
underpass-ui:
77+
container_name: "underpass_ui"
8978
build:
9079
context: .
9180
dockerfile: docker/underpass-ui.dockerfile
92-
target: debug
93-
args:
94-
APP_VERSION: ${APP_VERSION:-debug}
95-
# # Mount underpass-ui repo
9681
# volumes:
97-
# - ../underpass-ui/src:/code/src
98-
# - ../underpass-ui/playground:/code/playground
82+
# - js:/code
9983
ports:
100-
- "${UI_PORT:-5000}:5000"
84+
- "5000:5000"
10185
networks:
10286
internal:
10387

docker/ci-entrypoint.sh

-40
This file was deleted.

docker/underpass-api.dockerfile

+8-73
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,20 @@
11
FROM python:3.9
22

3-
FROM docker.io/python:${PYTHON_TAG}-slim-bookworm as base
4-
ARG APP_VERSION
5-
ARG COMMIT_REF
6-
LABEL org.hotosm.underpass.app-name="underpass-api" \
7-
org.hotosm.underpass.app-version="${APP_VERSION}" \
8-
org.hotosm.underpass.git-commit-ref="${COMMIT_REF:-none}" \
9-
org.hotosm.underpass.maintainer="[email protected]"
10-
RUN set -ex \
11-
&& apt-get update \
12-
&& DEBIAN_FRONTEND=noninteractive apt-get install \
13-
-y --no-install-recommends "locales" "ca-certificates" \
14-
&& DEBIAN_FRONTEND=noninteractive apt-get upgrade -y \
15-
&& rm -rf /var/lib/apt/lists/* \
16-
&& update-ca-certificates
17-
# Set locale
18-
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
19-
ENV LANG en_US.UTF-8
20-
ENV LANGUAGE en_US:en
21-
ENV LC_ALL en_US.UTF-8
3+
LABEL maintainer="Humanitarian OpenStreetMap Team" Description="This image provides the Underpass API" Vendor="HOT" Version="dev"
224

235
WORKDIR /code
246

257
RUN apt-get update && apt-get -y install \
268
postgresql \
279
libpq-dev
2810

29-
FROM base as build
30-
RUN set -ex \
31-
&& apt-get update \
32-
&& DEBIAN_FRONTEND=noninteractive apt-get install \
33-
-y --no-install-recommends \
34-
"build-essential" \
35-
"libpq-dev" \
36-
&& rm -rf /var/lib/apt/lists/*
37-
WORKDIR /opt/python
38-
COPY python/dbapi/requirements.txt /opt/python/requirements.txt
39-
COPY python/restapi/requirements.txt /opt/python/requirements2.txt
40-
RUN pip install --user --no-warn-script-location --no-cache-dir \
41-
-r /opt/python/requirements.txt -r /opt/python/requirements2.txt
11+
COPY ./python/dbapi /code/api/dbapi
12+
COPY ./python/restapi /code/api/restapi
4213

43-
FROM base as runtime
44-
ARG PYTHON_TAG
45-
ENV PYTHONDONTWRITEBYTECODE=1 \
46-
PYTHONUNBUFFERED=1 \
47-
PYTHONFAULTHANDLER=1 \
48-
PATH="/home/appuser/.local/bin:$PATH" \
49-
PYTHONPATH="/opt/restapi" \
50-
PYTHON_LIB="/home/appuser/.local/lib/python$PYTHON_TAG/site-packages" \
51-
SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt \
52-
REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt \
53-
CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
54-
RUN set -ex \
55-
&& apt-get update \
56-
&& DEBIAN_FRONTEND=noninteractive apt-get install \
57-
-y --no-install-recommends \
58-
"postgresql-client" \
59-
&& rm -rf /var/lib/apt/lists/*
60-
COPY --from=build \
61-
/root/.local \
62-
/home/appuser/.local
63-
COPY /python/dbapi /code/dbapi
64-
COPY /python/restapi /code/restapi
65-
WORKDIR /code/restapi
66-
# Add non-root user, permissions
67-
RUN useradd -r -u 1001 -m -c "hotosm account" -d /home/appuser -s /bin/false appuser \
68-
&& chown -R appuser:appuser /code /home/appuser
69-
# Change to non-root user
70-
USER appuser
71-
# Add Healthcheck
72-
HEALTHCHECK --start-period=10s --interval=5s --retries=12 --timeout=5s \
73-
CMD curl --fail http://localhost:8000 || exit 1
14+
RUN pip3 install -r /code/api/dbapi/requirements.txt
15+
RUN pip3 install -r /code/api/restapi/requirements.txt
7416

75-
FROM runtime as debug
76-
CMD ["uvicorn", "main:app", \
77-
"--host", "0.0.0.0", "--port", "8000", \
78-
"--reload", "--log-level", "critical", "--no-access-log"]
17+
WORKDIR /code/api/restapi
18+
19+
ENTRYPOINT ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
7920

80-
FROM runtime as prod
81-
# Pre-compile packages to .pyc (init speed gains)
82-
RUN python -c "import compileall; compileall.compile_path(maxlevels=10, quiet=1)"
83-
# Note: 4 uvicorn workers as running with docker, change to 1 worker for Kubernetes
84-
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", \
85-
"--workers", "4", "--log-level", "critical", "--no-access-log"]

0 commit comments

Comments
 (0)