diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..1714f237 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,39 @@ +name: CI + +on: [push] # FIXME: Temporarily avoid building PRs while setting up the CI + +jobs: + test: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + + - name: Set environment up + run: | + mv docker-compose.ci.yml docker-compose.override.yml + docker compose pull + docker compose up --wait db + docker compose build + docker compose exec db createdb planwise-test -U postgres + docker compose run --rm client npm install + + - name: Run specs + env: + JVM_OPTS: -Xmx3200m + run: | + docker compose up --wait db + docker compose run --rm -e JVM_OPTS app lein test + docker compose run --rm client npm run test + docker compose run --rm app lein check-format + + build: + needs: test + runs-on: ubuntu-22.04 + env: + DOCKER_REPOSITORY: 'instedd/planwise' + DOCKER_USER: ${{ secrets.DOCKER_USER }} + DOCKER_PASS: ${{ secrets.DOCKER_PASS }} + steps: + - uses: actions/checkout@v4 + - name: Build image & push to Docker Hub + run: ./build.sh diff --git a/Dockerfile b/Dockerfile index 79251375..8d4131d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,31 @@ +FROM clojure:lein-2.8.1 AS build + +RUN echo 'deb http://archive.debian.org/debian stretch main\n\ + deb http://archive.debian.org/debian-security stretch/updates main' > /etc/apt/sources.list + +RUN apt update && \ + apt install -y build-essential cmake \ + libboost-timer-dev libboost-program-options-dev \ + libboost-filesystem-dev \ + libpq-dev libgdal-dev postgresql-client libpq-dev \ + gdal-bin python-gdal libgdal-java \ + && \ + curl -sL https://deb.nodesource.com/setup_9.x | bash - && \ + apt-get install -y nodejs + +WORKDIR /app + +COPY . /app + +RUN cd client && npm install && npm run release +RUN lein uberjar +RUN scripts/build-binaries --release + FROM openjdk:8u242-jre-stretch +RUN echo 'deb http://archive.debian.org/debian stretch main\n\ + deb http://archive.debian.org/debian-security stretch/updates main' > /etc/apt/sources.list + # Install package dependencies and add precompiled binary RUN for i in {1..5}; do \ (apt-get update \ @@ -10,18 +36,24 @@ RUN for i in {1..5}; do \ && rm -rf /var/lib/apt/lists/* # Add scripts -ADD scripts/ /app/scripts/ +COPY --from=build /app/scripts/ /app/scripts/ ENV SCRIPTS_PATH /app/scripts/ # Add project compiled binaries -ADD cpp/build-linux-x86_64/aggregate-population /app/bin/aggregate-population -ADD cpp/build-linux-x86_64/walking-coverage /app/bin/walking-coverage +COPY --from=build /app/cpp/build-linux-x86_64/aggregate-population /app/bin/aggregate-population +COPY --from=build /app/cpp/build-linux-x86_64/walking-coverage /app/bin/walking-coverage ENV BIN_PATH /app/bin/ # Add uberjar with app -ADD ./target/uberjar/planwise-standalone.jar /app/lib/ +COPY --from=build /app/target/uberjar/planwise-standalone.jar /app/lib/ ENV JAR_PATH /app/lib/planwise-standalone.jar +# Add app version file +COPY --from=build /app/resources/planwise/version /app/VERSION + +# Expose JNI libs to app +ENV LD_LIBRARY_PATH=/usr/lib/jni + # Exposed port ENV PORT 80 EXPOSE $PORT diff --git a/Dockerfile-dev b/Dockerfile-dev index 1bd4bc93..c7b89a76 100644 --- a/Dockerfile-dev +++ b/Dockerfile-dev @@ -1,5 +1,8 @@ FROM clojure:lein-2.8.1 +RUN echo 'deb http://archive.debian.org/debian stretch main\n\ + deb http://archive.debian.org/debian-security stretch/updates main' > /etc/apt/sources.list + RUN apt update && \ apt install -y build-essential cmake \ libboost-timer-dev libboost-program-options-dev \ @@ -11,4 +14,3 @@ RUN apt update && \ apt-get install -y nodejs WORKDIR /app - diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..b652acf7 --- /dev/null +++ b/build.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -eo pipefail + +source <(curl -s https://raw.githubusercontent.com/manastech/ci-docker-builder/d3406587def914918666ef41c0637d6b739fdf7d/build.sh) + +dockerSetup +echo $VERSION > VERSION +echo $VERSION > resources/planwise/version + +dockerBuildAndPush +# FIXME: build & push mapcache +# FIXME: build & push mapserver +# FIXME: build & push tools diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml index 20ded0b4..b0f85422 100644 --- a/docker-compose.ci.yml +++ b/docker-compose.ci.yml @@ -2,9 +2,6 @@ version: '2' services: app: - volumes: - - .:/app - - ~/cache/.m2:/root/.m2 environment: DATABASE_URL: "jdbc:postgresql://db/planwise?user=postgres&password=planwise" TEST_DATABASE_URL: "jdbc:postgresql://db/planwise-test?user=postgres&password=planwise" diff --git a/docker-compose.yml b/docker-compose.yml index f2b11940..89e0758d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,11 +5,12 @@ services: build: dockerfile: Dockerfile-dev context: . + platform: linux/amd64 volumes: - ".:/app" - m2:/root/.m2 - - "~/.lein:/root/.lein" - links: + - "lein:/root/.lein" + depends_on: - db env_file: - ./docker-env @@ -22,6 +23,7 @@ services: build: dockerfile: Dockerfile-dev context: . + platform: linux/amd64 volumes: - ".:/app" - m2:/root/.m2 @@ -46,7 +48,7 @@ services: image: camptocamp/mapcache:1.4 volumes: - "./mapserver/mapcache.xml:/mapcache/mapcache.xml:ro" - links: + depends_on: - mapserver ports: - "5002:80" @@ -61,16 +63,18 @@ services: tools: image: instedd/planwise-tools + platform: linux/amd64 build: context: scripts env_file: - ./docker-env volumes: - "./data:/data" - links: + depends_on: - db volumes: db: + lein: m2: node_modules: