forked from testing/wiki
migrate to fastly deploy
This commit is contained in:
parent
78708a4f25
commit
d455aabb99
10 changed files with 3284 additions and 41 deletions
41
.github/workflows/build.yml
vendored
41
.github/workflows/build.yml
vendored
|
|
@ -1,41 +0,0 @@
|
|||
---
|
||||
name: mkdocs build
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: docker.io/rockylinux:9
|
||||
steps:
|
||||
- name: Install deps
|
||||
run: dnf -y install git python3 python3-pip
|
||||
|
||||
- name: setup ssh
|
||||
env:
|
||||
SSH_KEY: "${{ secrets.SSH_KEY }}"
|
||||
run: |
|
||||
mkdir -p ~/.ssh/
|
||||
echo "$SSH_KEY" > ~/.ssh/id_rsa
|
||||
chmod 0700 ~/.ssh/
|
||||
chmod 0600 ~/.ssh/id_rsa
|
||||
|
||||
- name: checkout
|
||||
env:
|
||||
GIT_SSH_COMMAND: "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
|
||||
run:
|
||||
git clone https://git.resf.org/$GITHUB_REPOSITORY.git $GITHUB_WORKSPACE
|
||||
|
||||
- name: Install python requirements
|
||||
run: python3 -m pip install -r requirements.txt
|
||||
|
||||
- name: Deploy
|
||||
env:
|
||||
GIT_SSH_COMMAND: "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
|
||||
GIT_AUTHOR_NAME: "Rocky Bot"
|
||||
GIT_AUTHOR_EMAIL: "auto@rockylinux.org"
|
||||
run: |
|
||||
git remote set-url origin ssh://git@git.resf.org:22220/$GITHUB_REPOSITORY.git
|
||||
python3 -m mkdocs gh-deploy --force
|
||||
160
.github/workflows/deploy.yml
vendored
Normal file
160
.github/workflows/deploy.yml
vendored
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
---
|
||||
name: Build and Deploy
|
||||
|
||||
concurrency:
|
||||
group: live
|
||||
cancel-in-progress: true
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build Documentation
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/rocky-linux/docs-builder:latest
|
||||
outputs:
|
||||
DOCS_SHA: ${{ steps.build-docs.outputs.docs-sha }}
|
||||
environment: live
|
||||
steps:
|
||||
- name: Checkout mkdocs config
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set docs SHA
|
||||
id: docs-sha
|
||||
working-directory: docs
|
||||
shell: bash
|
||||
run: echo "DOCS_SHA=$(git rev-parse --verify HEAD)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Cache mkdocs build
|
||||
uses: actions/cache@v4
|
||||
id: docs-cache
|
||||
with:
|
||||
path: ${{ github.workspace }}/build/site
|
||||
key: cache-docs-${{ inputs.cache-suffix }}-${{ steps.docs-sha.outputs.DOCS_SHA }}
|
||||
enableCrossOsArchive: true
|
||||
|
||||
# Cache pip's download/build cache + virtualenv
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cache/pip
|
||||
.venv
|
||||
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pip-
|
||||
|
||||
- name: Set up venv
|
||||
run: python3 -m venv .venv
|
||||
|
||||
- name: Install local dependencies
|
||||
shell: bash
|
||||
run: |
|
||||
source .venv/bin/activate
|
||||
pip install --requirement requirements.txt --upgrade-strategy only-if-needed
|
||||
|
||||
- name: Build Site
|
||||
if: steps.docs-cache.outputs.cache-hit != 'true'
|
||||
shell: bash
|
||||
run: |
|
||||
source .venv/bin/activate
|
||||
mkdocs build -d build/site
|
||||
|
||||
- name: Archive build artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build
|
||||
path: build/site
|
||||
|
||||
deploy:
|
||||
name: Deploy to Fastly
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/rocky-linux/docs-builder:latest
|
||||
environment: live
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
|
||||
- name: Restore cached build
|
||||
uses: actions/cache/restore@v4
|
||||
id: docs-cache
|
||||
with:
|
||||
path: ${{ github.workspace }}/build/site
|
||||
key: cache-docs-default-${{ needs.build.outputs.DOCS_SHA }}
|
||||
fail-on-cache-miss: false
|
||||
enableCrossOsArchive: true
|
||||
|
||||
- name: Retrieve build artifacts
|
||||
if: steps.docs-cache.outputs.cache-hit != 'true'
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: build
|
||||
path: build/site
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm install
|
||||
working-directory: ./compute-js
|
||||
|
||||
- name: Cache fastly compute package
|
||||
id: restore-fastly-cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ github.workspace }}/compute-js/pkg/*.tar.gz
|
||||
key: cache-fastly-${{ needs.build.outputs.DOCS_SHA }}
|
||||
|
||||
- name: Build Compute Package
|
||||
if: steps.restore-fastly-cache.outputs.cache-hit != 'true'
|
||||
run: npm run build
|
||||
working-directory: ./compute-js
|
||||
env:
|
||||
FASTLY_API_TOKEN: ${{ secrets.FASTLY_API_TOKEN }}
|
||||
|
||||
- name: Publish to Staging Collection
|
||||
run: |
|
||||
npx @fastly/compute-js-static-publish publish-content
|
||||
working-directory: ./compute-js
|
||||
env:
|
||||
FASTLY_API_TOKEN: ${{ secrets.FASTLY_API_TOKEN }}
|
||||
|
||||
# TODO: only run when src/index.js or static-publish.rc.js are modified
|
||||
- name: Deploy App
|
||||
if: steps.restore-fastly-cache.outputs.cache-hit != 'true'
|
||||
run: npm run fastly:deploy
|
||||
working-directory: ./compute-js
|
||||
env:
|
||||
FASTLY_API_TOKEN: ${{ secrets.FASTLY_API_TOKEN }}
|
||||
|
||||
- name: Output staging info
|
||||
run: |
|
||||
echo "🚀 Deployment completed!"
|
||||
|
||||
# - name: Notify documentation channel about deployment Success
|
||||
# uses: mattermost/action-mattermost-notify@master
|
||||
# if: success() && !cancelled()
|
||||
# with:
|
||||
# MATTERMOST_WEBHOOK_URL: ${{ secrets.MM_WEBHOOK_URL }}
|
||||
# MATTERMOST_CHANNEL: documentation
|
||||
# TEXT: |
|
||||
# [Deployment](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) was completed :white_check_mark:
|
||||
# MATTERMOST_USERNAME: "Github"
|
||||
#
|
||||
# - name: Notify documentation channel about deployment Failure
|
||||
# uses: mattermost/action-mattermost-notify@master
|
||||
# if: failure() && !cancelled()
|
||||
# with:
|
||||
# MATTERMOST_WEBHOOK_URL: ${{ secrets.MM_WEBHOOK_URL }}
|
||||
# MATTERMOST_CHANNEL: documentation
|
||||
# TEXT: |
|
||||
# [Deployment](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) failed :x:
|
||||
# MATTERMOST_USERNAME: "Github"
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
site
|
||||
.actrc
|
||||
4
compute-js/.gitignore
vendored
Normal file
4
compute-js/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
/node_modules
|
||||
/bin
|
||||
/pkg
|
||||
/static-publisher
|
||||
26
compute-js/fastly.toml
Normal file
26
compute-js/fastly.toml
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# This file describes a Fastly Compute package. To learn more visit:
|
||||
# https://www.fastly.com/documentation/reference/compute/fastly-toml
|
||||
|
||||
authors = ["infrastructure@rockylinux.org"]
|
||||
description = "Testing Team Wiki"
|
||||
language = "javascript"
|
||||
manifest_version = 3
|
||||
name = "testing.rocky.page"
|
||||
service_id = "tOARC4IK3ECRyFbz993Tv0"
|
||||
|
||||
[local_server]
|
||||
|
||||
[local_server.kv_stores]
|
||||
|
||||
[local_server.kv_stores.testing-wiki]
|
||||
file = "./static-publisher/kvstore.json"
|
||||
format = "json"
|
||||
|
||||
[scripts]
|
||||
build = "npm run build"
|
||||
|
||||
[setup]
|
||||
|
||||
[setup.kv_stores]
|
||||
|
||||
[setup.kv_stores.testing-wiki]
|
||||
2998
compute-js/package-lock.json
generated
Normal file
2998
compute-js/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
25
compute-js/package.json
Normal file
25
compute-js/package.json
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"name": "compute-js-static-site",
|
||||
"version": "0.1.0",
|
||||
"description": "Fastly Compute static site",
|
||||
"author": "you@example.com",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@fastly/cli": "^11.2.0",
|
||||
"@fastly/compute-js-static-publish": "^7.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fastly/js-compute": "^3.26.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.11.0"
|
||||
},
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev:publish": "npx @fastly/compute-js-static-publish publish-content --local",
|
||||
"dev:start": "fastly compute serve",
|
||||
"fastly:deploy": "fastly compute publish",
|
||||
"fastly:publish": "npx @fastly/compute-js-static-publish publish-content",
|
||||
"build": "js-compute-runtime ./src/index.js ./bin/main.wasm"
|
||||
}
|
||||
}
|
||||
32
compute-js/publish-content.config.js
Normal file
32
compute-js/publish-content.config.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Generated by @fastly/compute-js-static-publish.
|
||||
*/
|
||||
|
||||
// Commented items are defaults, feel free to modify and experiment!
|
||||
// See README for a detailed explanation of the configuration options.
|
||||
|
||||
/** @type {import('@fastly/compute-js-static-publish').PublishContentConfig} */
|
||||
const config = {
|
||||
rootDir: "../site",
|
||||
// excludeDirs: [ './node_modules' ],
|
||||
// excludeDotFiles: true,
|
||||
// includeWellKnown: true,
|
||||
// kvStoreAssetInclusionTest: (assetKey) => true,
|
||||
// contentCompression: [ 'br', 'gzip' ],
|
||||
// contentTypes: [
|
||||
// { test: /.custom$/, contentType: 'application/x-custom', text: false },
|
||||
// ],
|
||||
|
||||
// Server settings are saved to the KV Store per collection
|
||||
server: {
|
||||
publicDirPrefix: "",
|
||||
staticItems: [],
|
||||
allowedEncodings: [ 'br', 'gzip' ],
|
||||
spaFile: false,
|
||||
notFoundPageFile: "/404.html",
|
||||
autoExt: [],
|
||||
autoIndex: ["index.html","index.htm"],
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
24
compute-js/src/index.js
Normal file
24
compute-js/src/index.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/// <reference types="@fastly/js-compute" />
|
||||
import { env } from 'fastly:env';
|
||||
import { PublisherServer } from '@fastly/compute-js-static-publish';
|
||||
import rc from '../static-publish.rc.js';
|
||||
const publisherServer = PublisherServer.fromStaticPublishRc(rc);
|
||||
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));
|
||||
async function handleRequest(event) {
|
||||
|
||||
console.log('FASTLY_SERVICE_VERSION', env('FASTLY_SERVICE_VERSION'));
|
||||
|
||||
const request = event.request;
|
||||
|
||||
const response = await publisherServer.serveRequest(request);
|
||||
if (response != null) {
|
||||
return response;
|
||||
}
|
||||
|
||||
// Do custom things here!
|
||||
// Handle API requests, serve non-static responses, etc.
|
||||
|
||||
return new Response('Not found', { status: 404 });
|
||||
}
|
||||
13
compute-js/static-publish.rc.js
Normal file
13
compute-js/static-publish.rc.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* Generated by @fastly/compute-js-static-publish.
|
||||
*/
|
||||
|
||||
/** @type {import('@fastly/compute-js-static-publish').StaticPublishRc} */
|
||||
const rc = {
|
||||
kvStoreName: "testing-wiki",
|
||||
publishId: "default",
|
||||
defaultCollectionName: "live",
|
||||
staticPublisherWorkingDir: "./static-publisher",
|
||||
};
|
||||
|
||||
export default rc;
|
||||
Loading…
Add table
Add a link
Reference in a new issue