Skip to content

Commit

Permalink
feat: s5cmd-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
catusax committed Jul 21, 2023
1 parent 60150d2 commit e22c61c
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/s5cmd-sync_builder.yml
Original file line number Diff line number Diff line change
@@ -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 }}
14 changes: 14 additions & 0 deletions s5cmd-sync/README.md
Original file line number Diff line number Diff line change
@@ -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
```
5 changes: 5 additions & 0 deletions s5cmd-sync/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM peakcom/s5cmd

RUN mkdir /etc/cron
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["sh" ,"/entrypoint.sh" ]
35 changes: 35 additions & 0 deletions s5cmd-sync/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e22c61c

Please sign in to comment.