Skip to content

Commit

Permalink
Merge pull request #1 from fixpoint/fix-already-exists
Browse files Browse the repository at this point in the history
✨ Add `overwrite` option to allow overwriting `index.html` and else.
  • Loading branch information
lambdalisue authored Oct 24, 2022
2 parents c32e905 + b7e87b7 commit 6901113
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ FROM mcr.microsoft.com/azure-cli
RUN apk --no-cache add jq

COPY --from=mustache-downloader /usr/local/bin/mustache /usr/local/bin/mustache
COPY entrypoint.sh /entrypoint.sh
COPY docker-entrypoint.sh /docker-entrypoint.sh
COPY index.html.mustache /index.html.mustache

ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/docker-entrypoint.sh"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ steps:
with:
connection-string: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}
prefix: some/directory
overwrite: true
```
See [action.yml](./action.yml) for more detail.
Expand Down
27 changes: 16 additions & 11 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
name: 'azblob-generate-static-index'
description: 'Generate index.html for static web hosting on Azure Blob storage'
author: 'fixpoint'
name: "azblob-generate-static-index"
description: "Generate index.html for static web hosting on Azure Blob storage"
author: "fixpoint"
branding:
icon: 'list'
color: 'gray-dark'
icon: "list"
color: "gray-dark"
inputs:
connection-string:
description: 'Connection string'
description: "Connection string"
required: true
container:
description: 'Container name'
description: "Container name"
required: false
default: '$web'
default: "$web"
prefix:
description: 'Prefix for index.html'
description: "Prefix for index.html"
required: true
overwrite:
description: "Allow to overwrite index.html (true/false)"
required: true
default: "false"
runs:
using: 'docker'
image: 'Dockerfile'
using: "docker"
image: "Dockerfile"
args:
- ${{ inputs.connection-string }}
- ${{ inputs.container }}
- ${{ inputs.prefix }}
- ${{ inputs.overwrite }}
40 changes: 40 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
CONTAINER_STRING=$1
CONTAINER_NAME=$2
PREFIX=$3
OVERWRITE=$4

set -Cue

if [[ -z $CONTAINER_STRING ]]; then
echo "container string is not specified" >&2
exit 1
fi
if [[ -z $CONTAINER_NAME ]]; then
echo "container name is not specified" >&2
exit 1
fi
if [[ -z $PREFIX ]]; then
echo "prefix is not specified" >&2
exit 1
fi

OPTIONS=""
if [[ $OVERWRITE == "true" ]]; then
OPTIONS=" --overwrite"
fi

az storage blob list \
--connection-string $CONTAINER_STRING \
--container-name $CONTAINER_NAME \
--prefix $PREFIX/ \
| jq -r '{"items": [sort_by(.properties.lastModified) | reverse | .[] | select(.name | endswith("/index.html") | not)] }' \
| mustache /index.html.mustache \
> index.html

az storage blob upload \
--connection-string $CONTAINER_STRING \
--container-name $CONTAINER_NAME \
--name $PREFIX/index.html \
--file index.html \
$OPTIONS
13 changes: 0 additions & 13 deletions entrypoint.sh

This file was deleted.

0 comments on commit 6901113

Please sign in to comment.