diff --git a/.github/workflows/upload-static-assets.yaml b/.github/workflows/upload-static-assets.yaml new file mode 100644 index 000000000..03dbb32bc --- /dev/null +++ b/.github/workflows/upload-static-assets.yaml @@ -0,0 +1,27 @@ +name: upload-static-assets + +on: + push: + branches: [main] + paths: + - upload-static-assets/** + - '*.json' + - .github/workflows/upload-static-assets.yaml + pull_request: + branches: [main] + paths: + - upload-static-assets/** + - '*.json' + - .github/workflows/upload-static-assets.yaml + +jobs: + test: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v3 + - uses: ./upload-static-assets + with: + source-image: nginx + source-path: /usr/share/nginx/html + bucket-uri: s3://bucket/dir diff --git a/upload-static-assets/README.md b/upload-static-assets/README.md new file mode 100644 index 000000000..318903347 --- /dev/null +++ b/upload-static-assets/README.md @@ -0,0 +1,7 @@ +# upload-static-assets + +This is an action to extract static assets in a Docker image and upload them to S3 bucket. + +## Getting Started + +TODO diff --git a/upload-static-assets/action.yaml b/upload-static-assets/action.yaml new file mode 100644 index 000000000..e54d9b916 --- /dev/null +++ b/upload-static-assets/action.yaml @@ -0,0 +1,24 @@ +name: upload-static-assets +description: upload static assets from Docker image to S3 bucket + +inputs: + source-image: + description: source of Docker image + required: true + source-path: + description: source path in the Docker image + required: true + bucket-uri: + description: URI of the destination bucket, e.g. s3://bucket/dir + required: true + +runs: + using: composite + steps: + - id: main + shell: bash + run: exec bash ${{ github.action_path }}/main.sh + env: + SOURCE_IMAGE: ${{ inputs.source-image }} + SOURCE_PATH: ${{ inputs.source-path }} + BUCKET_URI: ${{ inputs.bucket-uri }} diff --git a/upload-static-assets/main.sh b/upload-static-assets/main.sh new file mode 100644 index 000000000..2b0df1cc2 --- /dev/null +++ b/upload-static-assets/main.sh @@ -0,0 +1,19 @@ +#/bin/bash +set -o pipefail +set -eux + +content_dir="$(mktemp -d)" +container_id="$(docker create "$SOURCE_IMAGE")" +docker cp "$container_id:$SOURCE_PATH" "$content_dir" +docker rm "$container_id" + +find "$content_dir" -type f + +docker run --rm amazon/aws-cli:latest --version +docker run --rm \ + -v /tmp:/tmp \ + -e AWS_ACCESS_KEY_ID \ + -e AWS_SECRET_ACCESS_KEY \ + -e AWS_SESSION_TOKEN \ + amazon/aws-cli:latest \ + s3 sync --no-progress "$content_dir" "$BUCKET_URI"