Upload to MinIO action

This commit is contained in:
Vladimir Levin 2023-08-06 16:59:43 +09:00
parent 7750205b8c
commit ffc338072e
5 changed files with 125 additions and 2 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.idea
.vscode

14
Dockerfile Normal file
View File

@ -0,0 +1,14 @@
FROM alpine/curl:8.2.1
LABEL authors="Vladimir <opa_oz> Levin"
RUN curl https://dl.min.io/client/mc/release/linux-amd64/mc \
--create-dirs \
-o $HOME/minio-binaries/mc
RUN chmod +x $HOME/minio-binaries/mc
RUN export PATH=$PATH:$HOME/minio-binaries/
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

View File

@ -1,2 +1,51 @@
# minio-upload
GitHub Action to upload files to MinIO
# MinIO Upload Github Action
Runs [minio client](https://min.io/docs/minio/linux/reference/minio-mc.html) to upload file(s) to MinIO (self-hosted as well)
## Usage
1. Upload a file
```yaml
- name: Upload to MinIO
uses: yakubique/minio-upload@v1
with:
endpoint: ${{ secrets.MINIO_ENDPOINT }}
access_key: ${{ secrets.MINIO_ACCESS_KEY }}
secret_key: ${{ secrets.MINIO_SECRET_KEY }}
bucket: my_bucket_name
source: ./my-build-1-0-1.tar.gz
# Leading slash is required
target: '/builds'
```
2. Upload a directory
```yaml
- name: Upload to MinIO
uses: yakubique/minio-upload@v1
with:
endpoint: ${{ secrets.MINIO_ENDPOINT }}
access_key: ${{ secrets.MINIO_ACCESS_KEY }}
secret_key: ${{ secrets.MINIO_SECRET_KEY }}
bucket: my_bucket_name
source: ./public
# Leading slash is required
target: '/my-awesome-site/public'
# If you omit the `recursive` argument, action only copies objects in the top level of the specified directory.
recursive: true
```
3. Upload to the insecure MinIO instance (_http-only_)
```yaml
- name: Upload to MinIO
uses: yakubique/minio-upload@v1
with:
endpoint: ${{ secrets.MINIO_ENDPOINT }}
access_key: ${{ secrets.MINIO_ACCESS_KEY }}
secret_key: ${{ secrets.MINIO_SECRET_KEY }}
bucket: my_bucket_name
source: ./access-log.1970.01.01.tar.gz
# Leading slash is required
target: '/logs'
# Disables TLS/SSL certificate verification. Allows TLS connectivity to servers with invalid certificates.
insecure: true
```

43
action.yml Normal file
View File

@ -0,0 +1,43 @@
name: MinIO Upload
description: Upload file(s) to MinIO instance (self-hosted as well)
author: "Vladimir <opa_oz> Levin"
inputs:
endpoint:
description: MinIO endpoint (use `insecure=true` for HTTP-only)
required: true
access_key:
description: MinIO access key
required: true
secret_key:
description: MinIO secret key
required: true
bucket:
description: Target bucket to upload file to
required: true
source:
description: File to upload (use `recursive=true` to upload directory)
required: true
target:
description: Target in MinIO's bucket (with a leading slash, default='/')
required: false
default: '/'
insecure:
description: Disables TLS/SSL certificate verification. Allows TLS connectivity to servers with invalid certificates.
required: false
default: 'false'
recursive:
description: If you specify a directory, you must also set `recursive=true` to recursively copy the contents of that directory. If you omit the `recursive` argument, action only copies objects in the top level of the specified directory.
required: false
default: 'false'
runs:
using: docker
image: Dockerfile
env:
YA_ENDPOINT: "${{ inputs.endpoint }}"
YA_ACCESS_KEY: "${{ inputs.access_key }}"
YA_SECRET_KEY: "${{ inputs.secret_key }}"
YA_INSECURE: "${{ inputs.insecure }}"
YA_RECURSIVE: "${{ inputs.recursive }}"
args:
- "${{ inputs.source }}"
- "${{ inputs.bucket }}${{ inputs.target }}"

15
entrypoint.sh Normal file
View File

@ -0,0 +1,15 @@
et -euxo pipefail
insecure_option=""
if [[ "$YA_INSECURE" == "true" ]]; then
insecure_option="--insecure"
fi
recursive_option=""
if [[ "$YA_INSECURE" == "true" ]]; then
recursive_option="--recursive"
fi
mc alias set ${insecure_option:+"$insecure_option"} target "$YA_ENDPOINT" "$YA_ACCESS_KEY" "$YA_SECRET_KEY"
mc ${insecure_option:+"$insecure_option"} cp ${recursive_option:+"$recursive_option"} $1 "target/$2"