diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..2b9edd38 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,22 @@ +# Ignore everything +** + +# Allow files and directories + +# Underpass +!src +!config +!setup +!docker/bzip2.pc +!autogen.sh +!configure.ac +!Makefile.am +!m4 +!dist +!docs +!ABOUT-NLS +!config.rpath +!docker/ci-entrypoint.sh + +# API +!python diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index cf518cef..06d250f5 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -6,9 +6,11 @@ on: - docs/** - mkdocs.yml branches: - - master + - master + permissions: contents: write + jobs: deploy: runs-on: ubuntu-latest diff --git a/.github/workflows/release_img.yml b/.github/workflows/release_img.yml new file mode 100644 index 00000000..c8dd2168 --- /dev/null +++ b/.github/workflows/release_img.yml @@ -0,0 +1,29 @@ +name: 🔧 Build Release Image + +on: + release: + types: [published] + # Allow manual trigger + workflow_dispatch: + +jobs: + underpass-build: + uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.1 + with: + dockerfile: docker/underpass.dockerfile + build_target: prod + image_name: ghcr.io/${{ github.repository }} + + api-build: + uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.1 + with: + dockerfile: docker/underpass-api.dockerfile + build_target: prod + image_name: ghcr.io/${{ github.repository }}/api + + ui-build: + uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.1 + with: + dockerfile: docker/underpass-ui.dockerfile + build_target: prod + image_name: ghcr.io/${{ github.repository }}/ui diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9de44030..d86713f8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,29 +1,27 @@ -name: 🧪 Build and test +name: 🧪 Build and Test on: push: branches: - master + pull_request: + branches: + - master paths: - src/** - .github/workflows/** - docker/** + # Allow manual trigger + workflow_dispatch: jobs: - 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 \ No newline at end of file + build-and-test: + uses: hotosm/gh-workflows/.github/workflows/test_compose.yml@1.4.1 + 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" diff --git a/.github/workflows/tests/pr_payload.json b/.github/workflows/tests/pr_payload.json new file mode 100644 index 00000000..265abb8a --- /dev/null +++ b/.github/workflows/tests/pr_payload.json @@ -0,0 +1,10 @@ +{ + "pull_request": { + "head": { + "ref": "feat/some-new-thing" + }, + "base": { + "ref": "master" + } + } +} diff --git a/.github/workflows/tests/push_payload.json b/.github/workflows/tests/push_payload.json new file mode 100644 index 00000000..07f80ac5 --- /dev/null +++ b/.github/workflows/tests/push_payload.json @@ -0,0 +1,4 @@ +{ + "base_ref ": "master", + "ref": "refs/heads/master" +} diff --git a/.github/workflows/tests/test_ci.sh b/.github/workflows/tests/test_ci.sh new file mode 100644 index 00000000..a7572d5c --- /dev/null +++ b/.github/workflows/tests/test_ci.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +set -e + +######################################## +# Note: run this from the repo root. +######################################## + +# Tests +act pull_request -W .github/workflows/tests.yml \ + -e .github/workflows/tests/pr_payload.json + +# Docs +act push -W .github/workflows/docs.yml \ + -e .github/workflows/tests/pr_payload.json + +# Release +act release -W .github/workflows/release_img.yml \ + -e .github/workflows/tests/push_payload.json diff --git a/ci/ci_local.sh b/ci/ci_local.sh index 0213d434..12c0dc4a 100755 --- a/ci/ci_local.sh +++ b/ci/ci_local.sh @@ -19,24 +19,12 @@ cd ${TEMP_DIR} make distclean -j `nproc` || true make clean -j `nproc` || true -DOCKER_DIR="${TEMP_DIR}" -DOCKER_COMPOSE_FILE="${DOCKER_DIR}/docker-compose.yml" -DOCKER_BASE_COMMAND="docker-compose -f ${DOCKER_COMPOSE_FILE}" +# Run CI +APP_VERSION=ci docker compose run underpass --exit-code-from=underpass -# Run the composition -${DOCKER_BASE_COMMAND} up -d +# Shut down containers +APP_VERSION=ci docker compose down -# Build Underpass Library and Binaries -${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`" - -# Build and Run Underpass Tests - broken: alway succeeds -${DOCKER_BASE_COMMAND} exec -T underpass sh -c "cd /code/build/src/testsuite/libunderpass.all && make check -j `nproc`" - -# Comment the cleanup lines below or exit here if you want to run additional -# tests from a console in the temp container, for instance with: -${DOCKER_BASE_COMMAND} exec underpass bash - -${DOCKER_BASE_COMMAND} down echo "Remove temporary folder ${TEMP_DIR}" sudo rm -rf ${TEMP_DIR} diff --git a/docker-compose.yml b/docker-compose.yml index 4b74239c..e0a74e16 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,11 +22,10 @@ version: "3" services: # Database postgis: - image: postgis/postgis:15-3.3 - # image: arm64v8/postgres:15.3-alpine3.18 + image: postgis/postgis:${POSTGIS_TAG:-15-3.3-alpine} container_name: "underpass_postgis" ports: - - "5439:5432" + - "${DB_PORT:-5439}:5432" environment: - POSTGRES_DB=underpass - POSTGRES_USER=underpass @@ -44,44 +43,60 @@ services: # Underpass underpass: + image: "ghcr.io/hotosm/underpass:${APP_VERSION:-debug}" container_name: "underpass" build: context: . dockerfile: docker/underpass.dockerfile + target: debug + args: + APP_VERSION: ${APP_VERSION:-debug} + depends_on: [postgis] environment: - REPLICATOR_UNDERPASS_DB_URL=underpass:underpass@postgis/underpass command: tail -f /dev/null volumes: - ./replication:/code/build/replication - # - ./:/code + # - ./:/code networks: internal: # Underpass API - underpass-api: + api: + image: "ghcr.io/hotosm/underpass/api:${APP_VERSION:-debug}" container_name: "underpass_api" build: context: . dockerfile: docker/underpass-api.dockerfile - # volumes: - # - ./python:/code/api + target: debug + args: + APP_VERSION: ${APP_VERSION:-debug} + depends_on: [underpass] + volumes: + - ./python:/code ports: - - "8000:8000" + - "${API_PORT:-8000}:8000" networks: internal: environment: - UNDERPASS_API_DB=postgresql://underpass:underpass@postgis/underpass # Underpass UI - underpass-ui: + ui: + image: "ghcr.io/hotosm/underpass/ui:${APP_VERSION:-debug}" container_name: "underpass_ui" build: context: . dockerfile: docker/underpass-ui.dockerfile + target: debug + args: + APP_VERSION: ${APP_VERSION:-debug} + # # Mount underpass-ui repo # volumes: - # - js:/code + # - ../underpass-ui/src:/code/src + # - ../underpass-ui/playground:/code/playground ports: - - "5000:5000" + - "${UI_PORT:-8080}:5000" networks: internal: diff --git a/docker/ci-entrypoint.sh b/docker/ci-entrypoint.sh new file mode 100644 index 00000000..8556f8cb --- /dev/null +++ b/docker/ci-entrypoint.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +set -euo pipefail + +yellow_echo() { + local message="$1" + local separator="--------------------------------------------------------" + local sep_length=${#separator} + local pad_length=$(( (sep_length - ${#message}) / 2 )) + local pad="" + + for ((i=0; i