diff --git a/Dockerfile b/Dockerfile index a8d205c..4abbe94 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,4 +7,6 @@ RUN apk add --no-cache minio minio-client bash date && \ COPY scripts /scripts RUN chmod +x /scripts/entrypoint.sh -ENTRYPOINT ["/scripts/entrypoint.sh"] \ No newline at end of file +EXPOSE 9000 9001 + +ENTRYPOINT ["/scripts/entrypoint.sh"] diff --git a/Makefile b/Makefile index b2ca825..31d1065 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ IMAGE_NAME ?= sparkfabrik/docker-minio IMAGE_TAG ?= latest +BUCKET_NAME ?= testbucket MINIO_ROOT_USER ?= minioadmin MINIO_ROOT_PASSWORD ?= minioadmin @@ -12,10 +13,21 @@ cli: build start: build @docker run \ - -e OSB_BUCKET=drupal \ + -e BUCKET_NAME=$(BUCKET_NAME) \ -e MINIO_ROOT_USER=$(MINIO_ROOT_USER) \ -e MINIO_ROOT_PASSWORD=$(MINIO_ROOT_PASSWORD) \ -e MINIO_BROWSER=on \ + -p 9000:9000 \ -p 9001:9001 \ -v ./initfiles:/docker-entrypoint-initfiles.d \ - $(IMAGE_NAME):$(IMAGE_TAG) \ No newline at end of file + $(IMAGE_NAME):$(IMAGE_TAG) + +aws-cli: + @docker run --rm -it \ + -e AWS_ACCESS_KEY_ID=$(MINIO_ROOT_USER) \ + -e AWS_SECRET_ACCESS_KEY=$(MINIO_ROOT_PASSWORD) \ + -e AWS_DEFAULT_REGION=us-east-1 \ + -e AWS_ENDPOINT_URL=http://localhost:9000 \ + --network host \ + --entrypoint bash \ + amazon/aws-cli -il \ No newline at end of file diff --git a/README.md b/README.md index 13c6c07..0c19208 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ This is a simple docker image for running a minio server. It is based on alpine linux and uses the minio and minio-client packages from the alpine package repository. -The `/scripts/entrypoint.sh` script is used to start the minio server. It is possible to configure the container to create and populate the new bucket at startup by setting the `OSB_BUCKET` environment variable and adding the seed files to the folder defined by the `INITFILES_FOLDER` environment variable. +The `/scripts/entrypoint.sh` script is used to start the minio server. It is possible to configure the container to create and populate the new bucket at startup by setting the `BUCKET_NAME` environment variable and adding the seed files to the folder defined by the `INITFILES_FOLDER` environment variable. diff --git a/scripts/common.sh b/scripts/common.sh index 9a3a32d..d9bf1d4 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -1,8 +1,9 @@ # Helper functions for the entrypoint script. docker_process_init_files() { if [ "$(ls "${INITFILES_FOLDER}" | wc -l)" -gt 0 ]; then - minio_note "Uploading files to bucket $bucket" - mc cp --recursive "${INITFILES_FOLDER}"/* "minio/${OSB_BUCKET}" + minio_note "Uploading files to bucket ${BUCKET_NAME}" + # Note the trailing slash in the source folder. This is required to copy the CONTENTS of the folder and not the folder itself. + mc cp --recursive "${INITFILES_FOLDER}/" "minio/${BUCKET_NAME}" fi } @@ -13,20 +14,20 @@ docker_create_bucket() { sleep 1 # Check if bucket exists, otherwise create it. - if [ -z "$(mc ls "minio/${OSB_BUCKET}" 2>&1 || true)" ]; then - minio_note "Bucket ${OSB_BUCKET} already exists" + if [ -z "$(mc ls "minio/${BUCKET_NAME}" 2>&1 || true)" ]; then + minio_note "Bucket ${BUCKET_NAME} already exists" else - minio_note "Creating bucket ${OSB_BUCKET}" + minio_note "Creating bucket ${BUCKET_NAME}" mc config host add minio http://localhost:9000 "${MINIO_ROOT_USER}" "${MINIO_ROOT_PASSWORD}" - mc mb -p "minio/${OSB_BUCKET}" - mc policy set public "minio/${OSB_BUCKET}" + mc mb -p "minio/${BUCKET_NAME}" + mc policy set public "minio/${BUCKET_NAME}" fi # Eventually process init files. docker_process_init_files # Stop minio server. - kill -9 $MINIO_TEMP_PID + kill -9 "${MINIO_TEMP_PID}" } # Logging functions. diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index b60813c..3a0e09f 100644 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -21,9 +21,15 @@ if [ -z "${MINIO_ROOT_PASSWORD}" ] && [ -n "${MINIO_SECRET_KEY}" ]; then export MINIO_ROOT_PASSWORD="${MINIO_SECRET_KEY}" fi +# Backward compatibility for OSB_BUCKET. +# The variable is overwritten if BUCKET_NAME is not set. +if [ -z "${BUCKET_NAME}" ] && [ -n "${OSB_BUCKET}" ]; then + export BUCKET_NAME="${OSB_BUCKET}" +fi + # Check required environment variables -if [ -z "${OSB_BUCKET}" ]; then - minio_error "OSB_BUCKET environment variable is required." +if [ -z "${BUCKET_NAME}" ]; then + minio_error "BUCKET_NAME environment variable is required." fi if [ -z "${MINIO_ROOT_USER}" ]; then