From 10f3eeeb15583bf51c220f2f0bff28a0b764393d Mon Sep 17 00:00:00 2001 From: Ricky Hosfelt Date: Thu, 25 Jan 2024 12:38:27 -0500 Subject: [PATCH] build static site --- .../hosfe.lt/public/posts/edge/index.html | 50 ++++++++++++++----- .../hosfe.lt/public/posts/index.xml | 42 ++++++++++++---- 2 files changed, 70 insertions(+), 22 deletions(-) diff --git a/src/static_site/hosfe.lt/public/posts/edge/index.html b/src/static_site/hosfe.lt/public/posts/edge/index.html index acd9e22..24a988c 100644 --- a/src/static_site/hosfe.lt/public/posts/edge/index.html +++ b/src/static_site/hosfe.lt/public/posts/edge/index.html @@ -21,7 +21,7 @@ - + @@ -34,7 +34,7 @@ It's 2024 and This Blog is Now On The Edge - +

Ricky Hosfelt

untagged

-

1730 Words +

1733 Words – - 7 Minutes, 51 Seconds

+ 7 Minutes, 52 Seconds

2024-01-05 09:18 -0500


@@ -113,7 +113,13 @@

How To Get StartedThere’s essentially two paths you have to work on in parallel the raw code for the blog and the setting up of the networking to point to the edge network to serve said code.

Some Warnings First

I am definitely not done with the blog that’s for sure! As well as I am very certain there are better ways to do things but I wanted to give a little insight into how I learned and pieced together the information to get this working. If you have any suggestion throw in an issue for me!

-

DISCLAIMER I am a Fastly employee (and very new). So anything in the blog does not speak for Fastly itself but my own personal experience using the products they provide.

+ +

Finally, this blog and post (and my life) will be centered around Rust. There’s plenty of resources for other languages (like JavaScript and Go, but I know very little about those).

The Blog’s Code

The main focus of this section will be my main.rs Rust module (on GitHub). The source HTML is also in there but that is less interesting and I will briefly cover that later.

@@ -130,18 +136,36 @@

Okay, But How Do You Get Started?First, I created my Fastly account and set it up in the following way to create an edge compute service.

Next, is to create a compute service. Do not worry about a domain or host for now you can set it to anything you want and change it later. We will use the test generated link and setup the networking later. Make sure to save your service_id as it will be necessary to push an update to that newly created service.

To use the Fastly CLI (next step) you’ll need a new token with permissions to do so. In the Fastly Management domain go to your Profile (upper right) > Account > API Tokens (lower left) and generate an API token with Global API Access both the first option (Global) for full control and Global Read (global:read is enable by default but write is not).

-

make _sure_ you save this token off as soon as you navigate away from this screen you will lose access to display the token again for security reasons.

-

make sure to keep this safe it's a secret. Just like any secret key, it could cost you money if you leak it. I suggest immediately storing it in a password manager like 1Password so you can access it safely and from the CLI (I'll show you how to do this as well). Finally, for security I do recommend letting this expire and generating a new one roughly every 6 months.

+ + + +

After that I installed the Fastly CLI (or you can do everything from the web if you prefer but I like using CLIs so I do when I can). For me that was as simple as following the brew install fastly/tap/fastly command.

Next up we’ll test out a working CLI interface. I use 1Password’s CLI to help insert secrets without leaking them (read the install instructions here: 1Password CLI); however, you can do what you are most comfortable with (both security and tool-wise). The command I would recommend running first is:

-
~# fastly whoami --token $(op item get "$YOUR_FASTLY_ITEM_NAME" --fields $YOUR_API_TOKEN_FIELD_NAME)
-

If you get an output with your name and email you are good to go! Otherwise it would appear the account token you’ve generated isn’t working or you have a previous configuration somewhere that is messing with it. Reach out to the Fastly Developer Docs or the Contact the community for additional help.

+
~ fastly whoami --token $(op item get "$YOUR_FASTLY_ITEM_NAME" --fields $YOUR_API_TOKEN_FIELD_NAME)
+

If you get an output with your name and email you are good to go! Otherwise it would appear the account token you’ve generated isn’t working or you have a previous configuration somewhere that is messing with it. Reach out to the Fastly Developer Docs or the Contact the community for additional help.

Once you have a successful result from whoami you’re ready to push to your service! I would recommend following the Rust template repository by forking it and pushing a single simple page (e.g. one match arm with the catchall as well) with anything you want. Do so by calling the following inside the template repo:

-
~# fastly compute publish --token $YOUR_TOKEN --service-id $YOUR_SERVICE_ID
-

Once that deploys you can check it via the Management portal, click on Compute > Your Service > Version Number > Then you should see “Test Domain” next to your domain.

+
~ fastly compute publish --token $YOUR_TOKEN --service-id $YOUR_SERVICE_ID
+

Once that deploys you can check it via the Management portal, click on Compute > Your Service > Version Number > Then you should see “Test Domain” next to your domain.

As you get more complex or if you want to test the binary locally you can do so very easily just:

-
~# fastly compute serve
-

That will create the binary and host it locally to 127.0.0.1:7676

+
~ fastly compute serve
+
+

There’s quite a few starter kits (including in different languages) on the Fastly Organization take a look through I just picked the one I found the simplest to get started!

Fastly’s Template Structure Explained

If you fork one of Fastly’s template repositories there’s some files in there that probably need a bit of explaining. I’ll quickly go over those.

diff --git a/src/static_site/hosfe.lt/public/posts/index.xml b/src/static_site/hosfe.lt/public/posts/index.xml index 13ca76c..c7e2101 100644 --- a/src/static_site/hosfe.lt/public/posts/index.xml +++ b/src/static_site/hosfe.lt/public/posts/index.xml @@ -31,7 +31,13 @@ I am taking advantage of learning at my new job by utilizing Fastly’s

There’s essentially two paths you have to work on in parallel the raw code for the blog and the setting up of the networking to point to the edge network to serve said code.

Some Warnings First

I am definitely not done with the blog that’s for sure! As well as I am very certain there are better ways to do things but I wanted to give a little insight into how I learned and pieced together the information to get this working. If you have any suggestion throw in an issue for me!

-

DISCLAIMER I am a Fastly employee (and very new). So anything in the blog does not speak for Fastly itself but my own personal experience using the products they provide.

+ +

Finally, this blog and post (and my life) will be centered around Rust. There’s plenty of resources for other languages (like JavaScript and Go, but I know very little about those).

The Blog’s Code

The main focus of this section will be my main.rs Rust module (on GitHub). The source HTML is also in there but that is less interesting and I will briefly cover that later.

@@ -48,18 +54,36 @@ I am taking advantage of learning at my new job by utilizing Fastly’s

First, I created my Fastly account and set it up in the following way to create an edge compute service.

Next, is to create a compute service. Do not worry about a domain or host for now you can set it to anything you want and change it later. We will use the test generated link and setup the networking later. Make sure to save your service_id as it will be necessary to push an update to that newly created service.

To use the Fastly CLI (next step) you’ll need a new token with permissions to do so. In the Fastly Management domain go to your Profile (upper right) > Account > API Tokens (lower left) and generate an API token with Global API Access both the first option (Global) for full control and Global Read (global:read is enable by default but write is not).

-

make _sure_ you save this token off as soon as you navigate away from this screen you will lose access to display the token again for security reasons.

-

make sure to keep this safe it's a secret. Just like any secret key, it could cost you money if you leak it. I suggest immediately storing it in a password manager like 1Password so you can access it safely and from the CLI (I'll show you how to do this as well). Finally, for security I do recommend letting this expire and generating a new one roughly every 6 months.

+ + + +

After that I installed the Fastly CLI (or you can do everything from the web if you prefer but I like using CLIs so I do when I can). For me that was as simple as following the brew install fastly/tap/fastly command.

Next up we’ll test out a working CLI interface. I use 1Password’s CLI to help insert secrets without leaking them (read the install instructions here: 1Password CLI); however, you can do what you are most comfortable with (both security and tool-wise). The command I would recommend running first is:

-
~# fastly whoami --token $(op item get "$YOUR_FASTLY_ITEM_NAME" --fields $YOUR_API_TOKEN_FIELD_NAME)
-

If you get an output with your name and email you are good to go! Otherwise it would appear the account token you’ve generated isn’t working or you have a previous configuration somewhere that is messing with it. Reach out to the Fastly Developer Docs or the Contact the community for additional help.

+
~ fastly whoami --token $(op item get "$YOUR_FASTLY_ITEM_NAME" --fields $YOUR_API_TOKEN_FIELD_NAME)
+

If you get an output with your name and email you are good to go! Otherwise it would appear the account token you’ve generated isn’t working or you have a previous configuration somewhere that is messing with it. Reach out to the Fastly Developer Docs or the Contact the community for additional help.

Once you have a successful result from whoami you’re ready to push to your service! I would recommend following the Rust template repository by forking it and pushing a single simple page (e.g. one match arm with the catchall as well) with anything you want. Do so by calling the following inside the template repo:

-
~# fastly compute publish --token $YOUR_TOKEN --service-id $YOUR_SERVICE_ID
-

Once that deploys you can check it via the Management portal, click on Compute > Your Service > Version Number > Then you should see “Test Domain” next to your domain.

+
~ fastly compute publish --token $YOUR_TOKEN --service-id $YOUR_SERVICE_ID
+

Once that deploys you can check it via the Management portal, click on Compute > Your Service > Version Number > Then you should see “Test Domain” next to your domain.

As you get more complex or if you want to test the binary locally you can do so very easily just:

-
~# fastly compute serve
-

That will create the binary and host it locally to 127.0.0.1:7676

+
~ fastly compute serve
+
+

There’s quite a few starter kits (including in different languages) on the Fastly Organization take a look through I just picked the one I found the simplest to get started!

Fastly’s Template Structure Explained

If you fork one of Fastly’s template repositories there’s some files in there that probably need a bit of explaining. I’ll quickly go over those.