mirror of https://github.com/docker/docs.git
ci: deploy static to netlify
Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com>
This commit is contained in:
parent
95652e0b3d
commit
802c071377
|
|
@ -0,0 +1 @@
|
|||
node_modules
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
FROM node:lts-alpine
|
||||
|
||||
RUN apk add --no-cache jq
|
||||
RUN npm i -g netlify-cli
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
ENTRYPOINT [ "/entrypoint.sh" ]
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
name: netlify action
|
||||
description: handle the integration with netlify
|
||||
inputs:
|
||||
netlify_token:
|
||||
description: Access token for netlify
|
||||
required: true
|
||||
netlify_account_slug:
|
||||
description: Account slug on netlify
|
||||
required: true
|
||||
site_name:
|
||||
description: Site name on netlify
|
||||
required: true
|
||||
directory:
|
||||
description: Directory containing the files to deploy
|
||||
required: true
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
args:
|
||||
- ${{ inputs.netlify_token }}
|
||||
- ${{ inputs.netlify_account_slug }}
|
||||
- ${{ inputs.site_name }}
|
||||
- ${{ inputs.directory }}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -xe
|
||||
|
||||
function usage() {
|
||||
echo "Usage: <netlify_auth_token> <netlify_account_slug> <site_name> <directory>"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function slug() {
|
||||
echo $1 | sed -E s/[^a-zA-Z0-9]+/-/g | sed -E s/^-+\|-+$//g | tr A-Z a-z
|
||||
}
|
||||
|
||||
function get_site_id() {
|
||||
netlify sites:list --json | jq --raw-output ".[] | select(.name==\"$1\") | .id"
|
||||
}
|
||||
|
||||
function get_site_url() {
|
||||
netlify sites:list --json | jq --raw-output ".[] | select(.name==\"$1\") | .url"
|
||||
}
|
||||
|
||||
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
export NETLIFY_AUTH_TOKEN=$1
|
||||
account_slug=$2
|
||||
site_name=$3
|
||||
directory=$4
|
||||
|
||||
clean_site_name=$(slug $site_name)
|
||||
|
||||
if [ -z "$(get_site_id $clean_site_name)" ]; then
|
||||
echo "creating site"
|
||||
netlify sites:create \
|
||||
--account-slug ${account_slug} \
|
||||
--manual \
|
||||
--name "${clean_site_name}"
|
||||
else
|
||||
echo "site already exists"
|
||||
fi
|
||||
|
||||
echo "fetching site id"
|
||||
|
||||
site_id=$(get_site_id ${clean_site_name})
|
||||
site_url=$(get_site_url ${clean_site_name})
|
||||
|
||||
echo
|
||||
echo "site id $site_id"
|
||||
echo "site url $site_url"
|
||||
echo ::set-output name=site_id::$site_id
|
||||
echo ::set-output name=site_url::$site_url
|
||||
echo
|
||||
|
||||
echo "deploy site"
|
||||
|
||||
netlify deploy --prod --dir ${directory} --site $site_id
|
||||
|
|
@ -14,3 +14,13 @@ jobs:
|
|||
- uses: actions/checkout@v2
|
||||
- name: build image
|
||||
run: docker build --build-arg=ENABLE_ARCHIVES=false --target=current -t documentation:latest .
|
||||
- name: copy static files
|
||||
if: github.repository == 'docker/docker.github.io'
|
||||
run: docker run -v ${PWD}:/output documentation:latest cp -r /usr/share/nginx/html /output/_site
|
||||
- uses: ./.github/actions/netlify-deploy
|
||||
if: github.repository == 'docker/docker.github.io'
|
||||
with:
|
||||
directory: _site
|
||||
netlify_token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
||||
netlify_account_slug: ${{ secrets.NETLIFY_ACCOUNT_SLUG }}
|
||||
site_name: "${{ github.repository }}/${{ github.head_ref }}"
|
||||
|
|
|
|||
Loading…
Reference in New Issue