Skip to content

Commit

Permalink
feat: s3cmd Docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
pagbrl committed Dec 18, 2023
1 parent ccf6762 commit 75527f2
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 53 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
38 changes: 38 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: main

on:
push:
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
main:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Run Buildx
run: |
docker buildx build \
--push \
--platform=linux/amd64,linux/arm64,linux/armhf \
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest -f ./Dockerfile ./
53 changes: 1 addition & 52 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,52 +1 @@
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
.DS_Store
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM alpine:3

LABEL org.opencontainers.image.source = "https://github.com/dataforgoodfr/d4g-s3cmd"
LABEL org.opencontainers.image.authors = "Data For Good"

RUN apk update
RUN apk add python3 py-pip py-setuptools git ca-certificates

RUN git clone https://github.com/s3tools/s3cmd.git /opt/s3cmd
RUN ln -s /opt/s3cmd/s3cmd /usr/bin/s3cmd

WORKDIR /opt

ADD ./entrypoint.sh /opt/entrypoint.sh

WORKDIR /
CMD ["/opt/entrypoint.sh"]
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# d4g-s3cmd
s3cmd Dockerizing for dataforgood

This repository is an attempt at creating a standard Docker image for our use of `s3cmd` at @dataforgoodfr.

The result is a lightweight image that can be configured fully with environment variables.
We use Scaleway so some configuration is tailored to their platform (notably the `host_base` and `host_bucket` configurations).

## Usage
Usage is documented in-script, to display the help menu use

```
docker run -it --rm ghcr.io/dataforgoodfr/d4g-s3cmd:latest help
```
88 changes: 88 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/bin/sh -xe

#
# main entry point to run s3cmd
#
S3CMD_PATH=/opt/s3cmd/s3cmd
usage() {
cat <<EOF
USAGE docker run -it --rm -v \$(pwd):/opt/local \\
-e ACCESS_KEY=<access_key> \\
-e SECRET_KEY=<secret_key> \\
-e S3_PATH="s3://<bucket_name>/<path>" \\
-e HOST_BASE="fr-par.scw.cloud" \\
-e BUCKET_REGION="fr-par" \\
ghcr.io/dataforgoodfr/d4g-s3cmd:latest \\
[push|pull|help]
This script will push or pull any directory mapped to /opt/local to/from an S3 bucket.
This image has been built with Scaleway's object storage in-mind, some configurations might
be compatible with that platform only.
Supported environment variables configurations :
ACCESS_KEY : AWS access key (Required)
SECRET_KEY : AWS secret key (Required)
S3_PATH : S3 path to sync to/from (Required)
HOST_BASE : AWS host base (Optional)
BUCKET_REGION : AWS bucket region (Optional)
EOF
exit 1
}

setup_colors() {
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
# shellcheck disable=SC2034
NOCOLOR='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m'
else
# shellcheck disable=SC2034
NOCOLOR='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW=''
fi
}

info() {
echo -e "${GREEN}$*${NOCOLOR}"
}

error() {
echo -e "${RED}$*${NOCOLOR}"
}

debug() {
if [ "$DEBUG" == 'true' ]; then
echo -e "$1"
fi
}

setup_colors
if ( $1 == "help" ); then
usage
fi

for $VAR in ACCESS_KEY SECRET_KEY S3_PATH; do
if [ -z "${!VAR}" ]; then
error "$VAR not set."
usage
fi
done

echo "" >> /.s3cfg
echo "use_https = True" >> /.s3cfg
echo "access_key = ${ACCESS_KEY}" >> /.s3cfg
echo "secret_key = ${SECRET_KEY}" >> /.s3cfg
if [ -z "${HOST_BASE}" ]; then
echo "host_base = ${HOST_BASE}" >> /.s3cfg
fi
if [ -z "${HOST_BUCKET}" ]; then
echo "host_bucket = ${HOST_BUCKET}" >> /.s3cfg
fi
if [ -z "${BUCKET_REGION}" ]; then
echo "bucket_location = ${BUCKET_REGION}" >> /.s3cfg
fi

if ( $1 == "push" ); then
${S3CMD_PATH} --config=/.s3cfg sync /opt/local ${S3_PATH}
fi

if ( $1 == "pull" ); then
${S3CMD_PATH} --config=/.s3cfg sync /opt/local/ ${S3_PATH}
fi

0 comments on commit 75527f2

Please sign in to comment.