This repository has been archived by the owner on Oct 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #449 from hotosm/revert-447-feature/ci
Revert "Merge: Optimise dockerfiles, fix ci, release images"
- Loading branch information
Showing
14 changed files
with
103 additions
and
377 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
name: 🧪 Build and Test | ||
name: 🧪 Build and test | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
paths: | ||
- src/** | ||
- .github/workflows/** | ||
- docker/** | ||
|
||
jobs: | ||
build-and-test: | ||
uses: hotosm/gh-workflows/.github/workflows/[email protected] | ||
with: | ||
image_name: ghcr.io/${{ github.repository }} | ||
build_dockerfile: docker/underpass.dockerfile | ||
compose_service: underpass | ||
compose_command: echo "Tests complete." | ||
# TODO update postgis image to use github repo var ${{ vars.POSTGIS_TAG }} | ||
cache_extra_imgs: | | ||
"docker.io/postgis/postgis:15-3.3-alpine" | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
# Relies on the master branch built docker image for build-deps | ||
- name: Start Docker Compose & build | ||
run: cd docker && docker-compose up -d underpass | ||
# Build and run tests | ||
- name: Build and run tests | ||
run: | | ||
docker-compose -f docker-compose.yml exec -T underpass sh -c "cd /code/build && make check -j `nproc`" | ||
exit_code=$? | ||
if [ $exit_code -ne 0 ]; then | ||
echo "Test failed with exit code $exit_code" | ||
exit $exit_code | ||
fi |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,20 @@ | ||
FROM python:3.9 | ||
|
||
FROM docker.io/python:${PYTHON_TAG}-slim-bookworm as base | ||
ARG APP_VERSION | ||
ARG COMMIT_REF | ||
LABEL org.hotosm.underpass.app-name="underpass-api" \ | ||
org.hotosm.underpass.app-version="${APP_VERSION}" \ | ||
org.hotosm.underpass.git-commit-ref="${COMMIT_REF:-none}" \ | ||
org.hotosm.underpass.maintainer="[email protected]" | ||
RUN set -ex \ | ||
&& apt-get update \ | ||
&& DEBIAN_FRONTEND=noninteractive apt-get install \ | ||
-y --no-install-recommends "locales" "ca-certificates" \ | ||
&& DEBIAN_FRONTEND=noninteractive apt-get upgrade -y \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& update-ca-certificates | ||
# Set locale | ||
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen | ||
ENV LANG en_US.UTF-8 | ||
ENV LANGUAGE en_US:en | ||
ENV LC_ALL en_US.UTF-8 | ||
LABEL maintainer="Humanitarian OpenStreetMap Team" Description="This image provides the Underpass API" Vendor="HOT" Version="dev" | ||
|
||
WORKDIR /code | ||
|
||
RUN apt-get update && apt-get -y install \ | ||
postgresql \ | ||
libpq-dev | ||
|
||
FROM base as build | ||
RUN set -ex \ | ||
&& apt-get update \ | ||
&& DEBIAN_FRONTEND=noninteractive apt-get install \ | ||
-y --no-install-recommends \ | ||
"build-essential" \ | ||
"libpq-dev" \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
WORKDIR /opt/python | ||
COPY python/dbapi/requirements.txt /opt/python/requirements.txt | ||
COPY python/restapi/requirements.txt /opt/python/requirements2.txt | ||
RUN pip install --user --no-warn-script-location --no-cache-dir \ | ||
-r /opt/python/requirements.txt -r /opt/python/requirements2.txt | ||
COPY ./python/dbapi /code/api/dbapi | ||
COPY ./python/restapi /code/api/restapi | ||
|
||
FROM base as runtime | ||
ARG PYTHON_TAG | ||
ENV PYTHONDONTWRITEBYTECODE=1 \ | ||
PYTHONUNBUFFERED=1 \ | ||
PYTHONFAULTHANDLER=1 \ | ||
PATH="/home/appuser/.local/bin:$PATH" \ | ||
PYTHONPATH="/opt/restapi" \ | ||
PYTHON_LIB="/home/appuser/.local/lib/python$PYTHON_TAG/site-packages" \ | ||
SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt \ | ||
REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt \ | ||
CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt | ||
RUN set -ex \ | ||
&& apt-get update \ | ||
&& DEBIAN_FRONTEND=noninteractive apt-get install \ | ||
-y --no-install-recommends \ | ||
"postgresql-client" \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
COPY --from=build \ | ||
/root/.local \ | ||
/home/appuser/.local | ||
COPY /python/dbapi /code/dbapi | ||
COPY /python/restapi /code/restapi | ||
WORKDIR /code/restapi | ||
# Add non-root user, permissions | ||
RUN useradd -r -u 1001 -m -c "hotosm account" -d /home/appuser -s /bin/false appuser \ | ||
&& chown -R appuser:appuser /code /home/appuser | ||
# Change to non-root user | ||
USER appuser | ||
# Add Healthcheck | ||
HEALTHCHECK --start-period=10s --interval=5s --retries=12 --timeout=5s \ | ||
CMD curl --fail http://localhost:8000 || exit 1 | ||
RUN pip3 install -r /code/api/dbapi/requirements.txt | ||
RUN pip3 install -r /code/api/restapi/requirements.txt | ||
|
||
FROM runtime as debug | ||
CMD ["uvicorn", "main:app", \ | ||
"--host", "0.0.0.0", "--port", "8000", \ | ||
"--reload", "--log-level", "critical", "--no-access-log"] | ||
WORKDIR /code/api/restapi | ||
|
||
ENTRYPOINT ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] | ||
|
||
FROM runtime as prod | ||
# Pre-compile packages to .pyc (init speed gains) | ||
RUN python -c "import compileall; compileall.compile_path(maxlevels=10, quiet=1)" | ||
# Note: 4 uvicorn workers as running with docker, change to 1 worker for Kubernetes | ||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", \ | ||
"--workers", "4", "--log-level", "critical", "--no-access-log"] |
Oops, something went wrong.