mirror of
https://github.com/docker/docs.git
synced 2026-03-27 14:28:47 +07:00
8
.github/actions/netlify-clean/Dockerfile
vendored
Normal file
8
.github/actions/netlify-clean/Dockerfile
vendored
Normal file
@@ -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" ]
|
||||
15
.github/actions/netlify-clean/action.yml
vendored
Normal file
15
.github/actions/netlify-clean/action.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
name: netlify action
|
||||
description: handle the integration with netlify
|
||||
inputs:
|
||||
netlify_token:
|
||||
description: Access token for netlify
|
||||
required: true
|
||||
site_name:
|
||||
description: Site name on netlify
|
||||
required: true
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
args:
|
||||
- ${{ inputs.netlify_token }}
|
||||
- ${{ inputs.site_name }}
|
||||
33
.github/actions/netlify-clean/entrypoint.sh
vendored
Executable file
33
.github/actions/netlify-clean/entrypoint.sh
vendored
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -xe
|
||||
|
||||
function usage() {
|
||||
echo "Usage: <netlify_auth_token> <site_name>"
|
||||
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"
|
||||
}
|
||||
|
||||
if [ -z "$1" ] || [ -z "$2" ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
export NETLIFY_AUTH_TOKEN=$1
|
||||
site_name=$2
|
||||
|
||||
|
||||
echo "searching site ${site_name}"
|
||||
|
||||
clean_site_name=$(slug $site_name)
|
||||
site_id=$(get_site_id $clean_site_name)
|
||||
|
||||
echo "deleting site"
|
||||
|
||||
netlify sites:delete --force "${site_id}"
|
||||
1
.github/actions/netlify-deploy/.gitignore
vendored
Normal file
1
.github/actions/netlify-deploy/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
node_modules
|
||||
8
.github/actions/netlify-deploy/Dockerfile
vendored
Normal file
8
.github/actions/netlify-deploy/Dockerfile
vendored
Normal file
@@ -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" ]
|
||||
23
.github/actions/netlify-deploy/action.yml
vendored
Normal file
23
.github/actions/netlify-deploy/action.yml
vendored
Normal file
@@ -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 }}
|
||||
57
.github/actions/netlify-deploy/entrypoint.sh
vendored
Executable file
57
.github/actions/netlify-deploy/entrypoint.sh
vendored
Executable file
@@ -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
|
||||
10
.github/workflows/build-pr.yml
vendored
10
.github/workflows/build-pr.yml
vendored
@@ -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 }}"
|
||||
|
||||
21
.github/workflows/clean-pr.yml
vendored
Normal file
21
.github/workflows/clean-pr.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
name: remove published site from netlify
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- closed
|
||||
|
||||
jobs:
|
||||
remove-site-from-netlify:
|
||||
name: build
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'docker/docker.github.io'
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
- name: delete from netlify
|
||||
uses: ./.github/actions/netlify-clean
|
||||
with:
|
||||
netlify_token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
||||
site_name: "${{ github.repository }}/${{ github.head_ref }}"
|
||||
Reference in New Issue
Block a user