diff --git a/.github/workflows/s5cmd-sync_builder.yml b/.github/workflows/s5cmd-sync_builder.yml new file mode 100644 index 0000000..57a42b3 --- /dev/null +++ b/.github/workflows/s5cmd-sync_builder.yml @@ -0,0 +1,48 @@ +name: s5cmd-sync + +on: + workflow_dispatch: null + schedule: + - cron: '0 10 */2 * *' # every 2 days at 10am + push: + branches: + - 'main' + paths: + - 's5cmd-sync/**' + - '.github/workflows/s5cmd-sync_builder.yml' + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Setup ENV + run: | + echo owner_lc=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v4 + with: + context: ./${{ github.workflow }} + push: true + platforms: linux/amd64,linux/arm64 + tags: ghcr.io/${{ env.owner_lc }}/${{ github.workflow }}:latest + labels: | + org.opencontainers.image.documentation=https://github.com/LinuxHub-Group/dockerfiles/blob/main/${{ github.workflow }}/README.md + org.opencontainers.image.authors=${{ github.repository_owner }} \ No newline at end of file diff --git a/s5cmd-sync/README.md b/s5cmd-sync/README.md new file mode 100644 index 0000000..f81c7f0 --- /dev/null +++ b/s5cmd-sync/README.md @@ -0,0 +1,14 @@ +# s5cmd-sync + +sync your files to s3 storage using s5cmd + +```shell +docker run -it --rm \ + -e AWS_ACCESS_KEY_ID=4e9a01106 \ + -e AWS_SECRET_ACCESS_KEY=5de0703e54e9 \ + -e S5CMD_ENDPOINT=https://bff48b41b.r2.cloudflarestorage.com \ + -e S5CMD_DESTINATION=s3://my-bucket/tttt/ \ + -e S5CMD_DELETE=true \ + -v /home/demo/test:/aws \ + ghcr.io/linuxhub-group/s5cmd-sync/s5cmd-sync +``` diff --git a/s5cmd-sync/dockerfile b/s5cmd-sync/dockerfile new file mode 100644 index 0000000..25acd0e --- /dev/null +++ b/s5cmd-sync/dockerfile @@ -0,0 +1,5 @@ +FROM peakcom/s5cmd + +RUN mkdir /etc/cron +COPY entrypoint.sh /entrypoint.sh +ENTRYPOINT ["sh" ,"/entrypoint.sh" ] \ No newline at end of file diff --git a/s5cmd-sync/entrypoint.sh b/s5cmd-sync/entrypoint.sh new file mode 100644 index 0000000..d7998aa --- /dev/null +++ b/s5cmd-sync/entrypoint.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +SYNCOPTIONS="" +OPTIONS="" + +if [ -n "$S5CMD_ENDPOINT" ]; then + OPTIONS="${OPTIONS} --endpoint-url $S5CMD_ENDPOINT" +fi + +if [ -n "$S5CMD_SSE" ]; then + SYNCOPTIONS="${SYNCOPTIONS} --sse $S5CMD_SSE" +fi + +if [ -n "$S5CMD_SSE_KMS_KEY_ID" ]; then + SYNCOPTIONS="${SYNCOPTIONS} --sse-kms-key-id $S5CMD_SSE_KMS_KEY_ID" +fi + +if [ -n "$S5CMD_EXPIRES" ]; then + SYNCOPTIONS="${SYNCOPTIONS} --expires $S5CMD_EXPIRES" +fi + +if [ -n "$S5CMD_DELETE" ]; then + SYNCOPTIONS="${SYNCOPTIONS} --delete" +fi + +SYNCOPTIONS="${SYNCOPTIONS} $S5CMD_EXCLUDES" + +if [ -z "$CRON_SCHEDULE" ]; then + CRON_SCHEDULE="* * * * *" +fi + +echo "$CRON_SCHEDULE cd /aws/ && /s5cmd ${OPTIONS} sync ${SYNCOPTIONS} . ${S5CMD_DESTINATION}" >/etc/cron/crontab + +crontab /etc/cron/crontab +crond -f