switch to use Fastly for deploying

This commit is contained in:
Neil Hanlon 2024-08-16 00:00:55 -04:00
parent cf37118113
commit 5999f383f9
Signed by: neil
GPG Key ID: 705BC21EC3C70F34
7 changed files with 2157 additions and 16 deletions

View File

@ -11,31 +11,31 @@ jobs:
image: docker.io/rockylinux:9
steps:
- name: Install deps
run: dnf -y upgrade && dnf -y install git python3 python3-pip cairo-devel
- 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
dnf -y upgrade
dnf -y install git python3 python3-pip cairo-devel
- 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: Build
run: |
python3 -m mkdocs build
- name: Install fastly CLI
run: |
dnf -y install \
npm \
https://github.com/fastly/cli/releases/download/v10.13.3/fastly_10.13.3_linux_amd64.rpm
- 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"
FASTLY_API_TOKEN: "${{ secrets.FASTLY_API_TOKEN }}"
run: |
git remote set-url origin ssh://git@git.resf.org:22220/$GITHUB_REPOSITORY.git
python3 -m mkdocs gh-deploy --force
pushd compute-js
npm install
fastly compute publish

4
compute-js/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/node_modules
/bin
/pkg
/static-publisher

11
compute-js/fastly.toml Normal file
View File

@ -0,0 +1,11 @@
# This file describes a Fastly Compute package. To learn more visit:
# https://www.fastly.com/documentation/reference/compute/fastly-toml
authors = ["FIXME@rocky.page"]
description = "FIXME"
language = "javascript"
manifest_version = 2
name = "FIXME.rocky.page"
[scripts]
build = "npm run build"

2051
compute-js/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

23
compute-js/package.json Normal file
View File

@ -0,0 +1,23 @@
{
"name": "FIXME",
"version": "0.1.0",
"description": "FIXME",
"author": "FIXME",
"type": "module",
"devDependencies": {
"@fastly/compute-js-static-publish": "^6.0.3"
},
"dependencies": {
"@fastly/js-compute": "^3.20.0"
},
"engines": {
"node": ">=18.0.0"
},
"license": "UNLICENSED",
"private": true,
"scripts": {
"deploy": "fastly compute deploy",
"prebuild": "npx @fastly/compute-js-static-publish --build-static",
"build": "js-compute-runtime ./src/index.js ./bin/main.wasm"
}
}

18
compute-js/src/index.js Normal file
View File

@ -0,0 +1,18 @@
/// <reference types="@fastly/js-compute" />
import { getServer } from '../static-publisher/statics.js';
const staticContentServer = getServer();
// eslint-disable-next-line no-restricted-globals
addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));
async function handleRequest(event) {
const response = await staticContentServer.serveRequest(event.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 });
}

View File

@ -0,0 +1,34 @@
/*
* Copyright Fastly, Inc.
* Licensed under the MIT license. See LICENSE file for details.
*/
// 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').StaticPublisherConfig} */
const config = {
rootDir: "../site",
staticContentRootDir: "./static-publisher",
// kvStoreName: false,
// excludeDirs: [ './node_modules' ],
// excludeDotFiles: true,
// includeWellKnown: true,
// contentAssetInclusionTest: (filename) => true,
// contentCompression: [ 'br', 'gzip' ], // For this config value, default is [] if kvStoreName is null.
// moduleAssetInclusionTest: (filename) => false,
// contentTypes: [
// { test: /.custom$/, contentType: 'application/x-custom', text: false },
// ],
server: {
publicDirPrefix: "",
staticItems: ["/assets/"],
// compression: [ 'br', 'gzip' ],
spaFile: false,
notFoundPageFile: "/404.html",
autoExt: [],
autoIndex: ["index.html","index.htm"],
},
};
export default config;