Skip to content

Commit

Permalink
fix: small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Monska85 committed Aug 1, 2024
1 parent d16d8e6 commit 556a1a9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
EXPOSE 9000 9001

ENTRYPOINT ["/scripts/entrypoint.sh"]
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
IMAGE_NAME ?= sparkfabrik/docker-minio
IMAGE_TAG ?= latest

BUCKET_NAME ?= testbucket
MINIO_ROOT_USER ?= minioadmin
MINIO_ROOT_PASSWORD ?= minioadmin

Expand All @@ -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)
$(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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
17 changes: 9 additions & 8 deletions scripts/common.sh
Original file line number Diff line number Diff line change
@@ -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
}

Expand All @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 556a1a9

Please sign in to comment.