From 92155092a5bd7015eccd7456f60981d8f6e33327 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Mon, 8 Apr 2024 19:38:48 -0400 Subject: [PATCH] feat: initial version with start+stop+build --- Dockerfile | 5 +++++ README.md | 6 ++++++ build.sh | 8 ++++++++ service.json | 3 +++ start.sh | 30 ++++++++++++++++++++++++++++++ stop.sh | 3 +++ 6 files changed, 55 insertions(+) create mode 100644 Dockerfile create mode 100755 build.sh create mode 100644 service.json create mode 100755 start.sh create mode 100755 stop.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..828bfd2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM registry:2 + +ENV REGISTRY_AUTH="htpasswd" +ENV REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm" +ENV REGISTRY_AUTH_HTPASSWD_PATH="/auth/htpasswd" diff --git a/README.md b/README.md index db5e500..ccc056a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ # Registry Private container registry to organize self-hosted services. + +## Setting up service credentials + +The `container-registry_auth` volume is pre-seeded with an empty `htpasswd` file that will hold the credentials for registry users. + +See `man htpasswd` for reference. diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..a934bf9 --- /dev/null +++ b/build.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +image_name=$(jq .service_name ./service.json -r) +image_version=0 + +podman build \ + -t "$image_name:$image_version" \ + . diff --git a/service.json b/service.json new file mode 100644 index 0000000..995c19d --- /dev/null +++ b/service.json @@ -0,0 +1,3 @@ +{ + "service_name": "container-registry" +} diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..2d89128 --- /dev/null +++ b/start.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +service_name=$(jq .service_name ./service.json -r) +image_name=$service_name +image_version=0 + +auth_volume="$service_name"_auth + +podman volume exists "$auth_volume" + +if [[ "$?" != "1" ]]; then + echo "Volume $auth_volume already exists." +else + podman volume create "$auth_volume" + htpasswd_parent=$(podman volume inspect "$auth_volume" | jq '.[0].Mountpoint' -r) + touch "$htpasswd_parent"/htpasswd + echo "Created volume $auth_volume and seeded with empty htpasswd." +fi + +podman pod create \ + --name "$service_name" \ + --replace \ + -p 5000:5000 \ + +podman run \ + -td \ + --pod "$service_name" \ + --name "$service_name"_app \ + -v "$auth_volume":/auth:ro \ + "$image_name:$image_version" diff --git a/stop.sh b/stop.sh new file mode 100755 index 0000000..565bac4 --- /dev/null +++ b/stop.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +podman pod stop "$(jq .service_name ./service.json -r)"