diff --git a/Makefile b/Makefile index a9f6d3c..87c8a63 100644 --- a/Makefile +++ b/Makefile @@ -1,35 +1,40 @@ # Variables # ------------------------------------------------------------------------------ -POSTGRES_IMAGE_ID=marcosgabarda/postgres -POSTGIS_IMAGE_ID=marcosgabarda/postgis +POSTGRES_IMAGE_ID := marcosgabarda/postgres +POSTGIS_IMAGE_ID := marcosgabarda/postgis -.PHONY: build_postgres push_postgres build_postgis push_postgis +# Versions to build +# ------------------------------------------------------------------------------ +POSTGRES_VERSIONS := 10 11 12 13 14 15 +POSTGRES_LATEST_VERSION := 16 +POSTGIS_VERSIONS := 11-2.5 12-3.0 13-3.1 14-3.4 15-3.4 +POSTGIS_LATEST_VERSION := 16-3.4 + +.PHONY: build_postgres push_postgres build_postgis push_postgis build push build_postgres: - docker buildx build . -f ./postgres/10/Dockerfile --tag ${POSTGRES_IMAGE_ID}:10 --platform linux/amd64,linux/arm64 - docker buildx build . -f ./postgres/11/Dockerfile --tag ${POSTGRES_IMAGE_ID}:11 --platform linux/amd64,linux/arm64 - docker buildx build . -f ./postgres/12/Dockerfile --tag ${POSTGRES_IMAGE_ID}:12 --platform linux/amd64,linux/arm64 - docker buildx build . -f ./postgres/13/Dockerfile --tag ${POSTGRES_IMAGE_ID}:13 --platform linux/amd64,linux/arm64 - docker buildx build . -f ./postgres/14/Dockerfile --tag ${POSTGRES_IMAGE_ID}:14 --tag ${POSTGRES_IMAGE_ID}:latest --platform linux/amd64,linux/arm64 + @for version in $(POSTGRES_VERSIONS) ; do \ + docker buildx build . -f ./postgres/$$version/Dockerfile --tag ${POSTGRES_IMAGE_ID}:$$version --platform linux/amd64,linux/arm64 ; \ + done + docker buildx build . -f ./postgres/${POSTGRES_LATEST_VERSION}/Dockerfile --tag ${POSTGRES_IMAGE_ID}:${POSTGRES_LATEST_VERSION} --tag ${POSTGRES_IMAGE_ID}:latest --platform linux/amd64,linux/arm64 push_postgres: - docker buildx build . -f ./postgres/10/Dockerfile --tag ${POSTGRES_IMAGE_ID}:10 --platform linux/amd64,linux/arm64 --push - docker buildx build . -f ./postgres/11/Dockerfile --tag ${POSTGRES_IMAGE_ID}:11 --platform linux/amd64,linux/arm64 --push - docker buildx build . -f ./postgres/12/Dockerfile --tag ${POSTGRES_IMAGE_ID}:12 --platform linux/amd64,linux/arm64 --push - docker buildx build . -f ./postgres/13/Dockerfile --tag ${POSTGRES_IMAGE_ID}:13 --platform linux/amd64,linux/arm64 --push - docker buildx build . -f ./postgres/14/Dockerfile --tag ${POSTGRES_IMAGE_ID}:14 --tag ${POSTGRES_IMAGE_ID}:latest --platform linux/amd64,linux/arm64 --push + @for version in $(POSTGRES_VERSIONS) ; do \ + docker buildx build . -f ./postgres/$$version/Dockerfile --tag ${POSTGRES_IMAGE_ID}:$$version --platform linux/amd64,linux/arm64 --push ; \ + done + docker buildx build . -f ./postgres/${POSTGRES_LATEST_VERSION}/Dockerfile --tag ${POSTGRES_IMAGE_ID}:${POSTGRES_LATEST_VERSION} --tag ${POSTGRES_IMAGE_ID}:latest --platform linux/amd64,linux/arm64 --push build_postgis: - docker buildx build . -f ./postgis/11/Dockerfile --tag ${POSTGIS_IMAGE_ID}:11-2.5 --tag ${POSTGIS_IMAGE_ID}:11 --platform linux/amd64,linux/arm64 - docker buildx build . -f ./postgis/12/Dockerfile --tag ${POSTGIS_IMAGE_ID}:12-3.0 --tag ${POSTGIS_IMAGE_ID}:12 --platform linux/amd64,linux/arm64 - docker buildx build . -f ./postgis/13/Dockerfile --tag ${POSTGIS_IMAGE_ID}:13-3.1 --tag ${POSTGIS_IMAGE_ID}:13 --platform linux/amd64,linux/arm64 - docker buildx build . -f ./postgis/14/Dockerfile --tag ${POSTGIS_IMAGE_ID}:14-3.4 --tag ${POSTGIS_IMAGE_ID}:13 --tag ${POSTGIS_IMAGE_ID}:latest --platform linux/amd64,linux/arm64 + @for version in $(POSTGIS_VERSIONS) ; do \ + docker buildx build . -f ./postgis/$$version/Dockerfile --tag ${POSTGIS_IMAGE_ID}:$$version --tag ${POSTGIS_IMAGE_ID}:$(word 1, $(subst -, ,$$version)) --platform linux/amd64,linux/arm64 ; \ + done + docker buildx build . -f ./postgis/${POSTGIS_LATEST_VERSION}/Dockerfile --tag ${POSTGIS_IMAGE_ID}:${POSTGIS_LATEST_VERSION} --tag ${POSTGIS_IMAGE_ID}:$(word 1, $(subst -, ,$(POSTGIS_LATEST_VERSION))) --tag ${POSTGIS_IMAGE_ID}:latest --platform linux/amd64,linux/arm64 push_postgis: - docker buildx build . -f ./postgis/11/Dockerfile --tag ${POSTGIS_IMAGE_ID}:11-2.5 --tag ${POSTGIS_IMAGE_ID}:11 --platform linux/amd64,linux/arm64 --push - docker buildx build . -f ./postgis/12/Dockerfile --tag ${POSTGIS_IMAGE_ID}:12-3.0 --tag ${POSTGIS_IMAGE_ID}:12 --platform linux/amd64,linux/arm64 --push - docker buildx build . -f ./postgis/13/Dockerfile --tag ${POSTGIS_IMAGE_ID}:13-3.1 --tag ${POSTGIS_IMAGE_ID}:13 --platform linux/amd64,linux/arm64 --push - docker buildx build . -f ./postgis/14/Dockerfile --tag ${POSTGIS_IMAGE_ID}:14-3.4 --tag ${POSTGIS_IMAGE_ID}:14 --tag ${POSTGIS_IMAGE_ID}:latest --platform linux/amd64,linux/arm64 --push + @for version in $(POSTGIS_VERSIONS) ; do \ + docker buildx build . -f ./postgis/$$version/Dockerfile --tag ${POSTGIS_IMAGE_ID}:$$version --tag ${POSTGIS_IMAGE_ID}:$(word 1, $(subst -, ,$$version)) --platform linux/amd64,linux/arm64 --push ; \ + done + docker buildx build . -f ./postgis/${POSTGIS_LATEST_VERSION}/Dockerfile --tag ${POSTGIS_IMAGE_ID}:${POSTGIS_LATEST_VERSION} --tag ${POSTGIS_IMAGE_ID}:14 --tag ${POSTGIS_IMAGE_ID}:latest --platform linux/amd64,linux/arm64 --push build: build_postgres build_postgis diff --git a/README.md b/README.md index c5821dd..74904ae 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ To build the images and push them to the registry: Example of a `docker-compose.yml` file that uses this image: +```yaml version: '3' volumes: @@ -32,3 +33,36 @@ Example of a `docker-compose.yml` file that uses this image: - postgres_backups:/backups env_file: - ./.env +``` + +## Maintenance commands + +This images adds commands to the original PostgreSQL image for maintenance proposes. + +### Create a database backup + +Creates a backup of the database. Usage: + + $ docker-compose -f .yml (exec |run --rm) postgres backup + +### View backups + +Views a list of all created backups of the database. Usage: + + $ docker-compose -f .yml (exec |run --rm) postgres backups + +### Creates a read only user + +Creates a read only user. Usage: + + $ docker-compose -f .yml (exec |run --rm) postgres createreaduser + +### Restore database from a backup + +Restores the indicated database backup. Usage: + + $ docker-compose -f .yml (exec |run --rm) postgres restore <1> + +Parameters: + + * `<1>` filename of an existing backup. diff --git a/postgis/11/Dockerfile b/postgis/11-2.5/Dockerfile similarity index 100% rename from postgis/11/Dockerfile rename to postgis/11-2.5/Dockerfile diff --git a/postgis/12/Dockerfile b/postgis/12-3.0/Dockerfile similarity index 100% rename from postgis/12/Dockerfile rename to postgis/12-3.0/Dockerfile diff --git a/postgis/13/Dockerfile b/postgis/13-3.1/Dockerfile similarity index 100% rename from postgis/13/Dockerfile rename to postgis/13-3.1/Dockerfile diff --git a/postgis/14/Dockerfile b/postgis/14-3.4/Dockerfile similarity index 100% rename from postgis/14/Dockerfile rename to postgis/14-3.4/Dockerfile diff --git a/postgis/15-3.4/Dockerfile b/postgis/15-3.4/Dockerfile new file mode 100644 index 0000000..79cdaac --- /dev/null +++ b/postgis/15-3.4/Dockerfile @@ -0,0 +1,6 @@ +FROM postgis/postgis:15-3.4-alpine + +COPY ./maintenance /usr/local/bin/maintenance +RUN chmod +x /usr/local/bin/maintenance/* +RUN mv /usr/local/bin/maintenance/* /usr/local/bin \ + && rmdir /usr/local/bin/maintenance diff --git a/postgis/16-3.4/Dockerfile b/postgis/16-3.4/Dockerfile new file mode 100644 index 0000000..28e7b49 --- /dev/null +++ b/postgis/16-3.4/Dockerfile @@ -0,0 +1,6 @@ +FROM postgis/postgis:16-3.4-alpine + +COPY ./maintenance /usr/local/bin/maintenance +RUN chmod +x /usr/local/bin/maintenance/* +RUN mv /usr/local/bin/maintenance/* /usr/local/bin \ + && rmdir /usr/local/bin/maintenance diff --git a/postgres/15/Dockerfile b/postgres/15/Dockerfile new file mode 100644 index 0000000..7c9dec5 --- /dev/null +++ b/postgres/15/Dockerfile @@ -0,0 +1,6 @@ +FROM postgres:15 + +COPY ./maintenance /usr/local/bin/maintenance +RUN chmod +x /usr/local/bin/maintenance/* +RUN mv /usr/local/bin/maintenance/* /usr/local/bin \ + && rmdir /usr/local/bin/maintenance diff --git a/postgres/16/Dockerfile b/postgres/16/Dockerfile new file mode 100644 index 0000000..d8ade08 --- /dev/null +++ b/postgres/16/Dockerfile @@ -0,0 +1,6 @@ +FROM postgres:16 + +COPY ./maintenance /usr/local/bin/maintenance +RUN chmod +x /usr/local/bin/maintenance/* +RUN mv /usr/local/bin/maintenance/* /usr/local/bin \ + && rmdir /usr/local/bin/maintenance