-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate docker images automatically (#415)
* Generate docker images automatically * Modify docker section of README * Add test script to build docker images
- Loading branch information
Showing
5 changed files
with
169 additions
and
4 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
name: Docker image | ||
on: | ||
push: | ||
branches: | ||
- 'develop' | ||
tags: | ||
- 'v[0-9]+.[0-9]+.[0-9]+' | ||
|
||
jobs: | ||
build: | ||
name: Build & push docker image | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
psql: [12,13,14,15,16] | ||
postgis: [3.4] | ||
os: [ubuntu-latest] | ||
|
||
env: | ||
IMG_NAME: ${{ github.repository }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/[email protected] | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
# list of Docker images to use as base name for tags | ||
images: mobilitydb/mobilitydb | ||
# generate Docker tags based on the following events/attributes | ||
flavor: | | ||
latest=${{ matrix.psql == '16' && github.ref_type == 'tag' }} | ||
prefix=${{ matrix.psql }}-${{ matrix.postgis }}- | ||
tags: | | ||
type=ref,event=branch | ||
type=semver,pattern={{major}}.{{minor}} | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
with: | ||
# Add linux/arm64 when postgis builds arm64 version | ||
platforms: linux/amd64 | ||
|
||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
# Add linux/arm64 when postgis builds arm64 version | ||
platforms: linux/amd64 | ||
context: . | ||
file: ./docker/Dockerfile | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
build-args: | | ||
POSTGRES_VERSION=${{ matrix.psql }} | ||
POSTGIS_VERSION=${{ matrix.postgis }} | ||
MOBILITYDB_TAG=${{ github.ref_name }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
ARG POSTGRES_VERSION | ||
ARG POSTGIS_VERSION | ||
|
||
FROM postgis/postgis:$POSTGRES_VERSION-$POSTGIS_VERSION | ||
|
||
# Configuration Parameters | ||
LABEL maintainer="MobilityDB Project - https://github.com/MobilityDB/MobilityDB" | ||
|
||
# Fix the Release file expired problem | ||
RUN printf "Acquire::Check-Valid-Until \"false\";\nAcquire::Check-Date \"false\";" | cat > /etc/apt/apt.conf.d/10no--check-valid-until | ||
|
||
ARG MOBILITYDB_TAG | ||
|
||
# 1. Install Prerequisites | ||
# 2. Get, build and install MobilityDB | ||
# 3. Uninstall prerequisites | ||
RUN apt-get update \ | ||
&& apt-get install -y --no-install-recommends \ | ||
build-essential \ | ||
cmake \ | ||
wget \ | ||
libproj-dev \ | ||
libjson-c-dev \ | ||
libgsl-dev \ | ||
libgeos-dev \ | ||
postgresql-server-dev-"${PG_MAJOR}" \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& wget -O MobilityDB.tar.gz "https://github.com/MobilityDB/MobilityDB/archive/$MOBILITYDB_TAG.tar.gz" \ | ||
&& mkdir -p /usr/local/src/MobilityDB/build \ | ||
&& tar \ | ||
--extract \ | ||
--file MobilityDB.tar.gz \ | ||
--directory /usr/local/src/MobilityDB \ | ||
--strip-components 1 \ | ||
&& rm MobilityDB.tar.gz \ | ||
&& cd /usr/local/src/MobilityDB/build \ | ||
&& cmake .. \ | ||
&& make -j"$(nproc)" \ | ||
&& make install \ | ||
&& cp ../docker/initdb-mobilitydb.sh /docker-entrypoint-initdb.d/11_mobilitydb.sh \ | ||
&& cd / \ | ||
&& rm -rf /usr/local/src/MobilityDB \ | ||
&& apt-get purge -y --auto-remove \ | ||
build-essential \ | ||
cmake \ | ||
wget \ | ||
postgresql-server-dev-"${PG_MAJOR}" |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
echo "shared_preload_libraries = 'postgis-3.so'" >> "$PGDATA"/postgresql.conf | ||
|
||
# Perform all actions as $POSTGRES_USER | ||
export PGUSER="$POSTGRES_USER" | ||
|
||
# Create the 'template_mobilitydb' template db | ||
"${psql[@]}" <<- 'EOSQL' | ||
CREATE DATABASE template_mobilitydb IS_TEMPLATE true; | ||
EOSQL | ||
|
||
# Load mobilitydb into both template_database and $POSTGRES_DB | ||
# Since $POSTGRES_DB already has postgis, we must use | ||
# LOAD 'postgis-3.so' to be able to create the mobilitydb extension | ||
# (the shared_preload_libraries setting above has not taken effect yet) | ||
for DB in template_mobilitydb "$POSTGRES_DB"; do | ||
echo "Loading mobilitydb extensions into $DB" | ||
"${psql[@]}" --dbname="$DB" <<-'EOSQL' | ||
CREATE EXTENSION IF NOT EXISTS postgis; | ||
LOAD 'postgis-3.so'; | ||
CREATE EXTENSION IF NOT EXISTS mobilitydb; | ||
EOSQL | ||
done |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
set -Eeo pipefail | ||
# shellcheck disable=SC2043 | ||
|
||
# mobilitydb local build matrix | ||
for mobilitydb_ver in develop ; do | ||
for pg_major in 16 15 14 13 12 ; do | ||
for postgis_ver in 3.4 ; do | ||
docker build --pull --progress=plain \ | ||
--build-arg POSTGRES_VERSION=$pg_major \ | ||
--build-arg POSTGIS_VERSION=$postgis_ver \ | ||
--build-arg MOBILITYDB_TAG=$mobilitydb_ver \ | ||
-t testmobilitydb:${pg_major}-${postgis_ver}-${mobilitydb_ver} \ | ||
-f docker/Dockerfile\ | ||
. | ||
done | ||
done | ||
done |