Merge pull request #13 from Pagwin-Fedora/development

changing the github actions around a bit also blog v2 article stuff
This commit is contained in:
Pagwin 2023-09-14 14:46:52 -04:00 committed by GitHub
commit a3cbf40342
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 196 additions and 26 deletions

View file

@ -1,38 +1,78 @@
name: Website publish
name: Website containerize
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Code Checkout
uses: actions/checkout@v2
with:
submodules: true
fetch-depth: 0
- name: Hugo Setup
uses: peaceiris/actions-hugo@v2
with:
hugo-version: '0.91.2'
- name: Build
run: hugo --minify
- name: Clean
uses: appleboy/ssh-action@master
with:
host: pagwin.xyz
username: website
key: ${{secrets.SSH_KEY}}
script: rm -rf /var/www/pagwin.xyz/*
- name: Deploy
uses: up9cloud/action-rsync@master
# copied everything below this line from https://docs.github.com/en/actions/publishing-packages/publishing-docker-images
env:
HOST: pagwin.xyz
USER: website
KEY: ${{secrets.SSH_KEY}}
SOURCE: ./public/*
TARGET: /var/www/pagwin.xyz/
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
#jobs:
# build:
# runs-on: ubuntu-latest
# steps:
## old steps when I was deploying straight to VPS
# - name: Code Checkout
# uses: actions/checkout@v2
# with:
# submodules: true
# fetch-depth: 0
# - name: Hugo Setup
# uses: peaceiris/actions-hugo@v2
# with:
# hugo-version: '0.91.2'
# - name: Build
# run: hugo --minify
# - name: Clean
# uses: appleboy/ssh-action@master
# with:
# host: pagwin.xyz
# username: website
# key: ${{secrets.SSH_KEY}}
# script: rm -rf /var/www/pagwin.xyz/*
# - name: Deploy
# uses: up9cloud/action-rsync@master
# env:
# HOST: pagwin.xyz
# USER: website
# KEY: ${{secrets.SSH_KEY}}
# SOURCE: ./public/*
# TARGET: /var/www/pagwin.xyz/
#

24
Dockerfile Normal file
View file

@ -0,0 +1,24 @@
FROM alpine:3.18 as build
# making my own image for hugo because there doesn't seem to be an official one in repo, lazy so we're going with alpine
RUN ["apk", "update"]
RUN ["apk", "add", "hugo"]
ADD . /root/
WORKDIR /root
# pass in the uri or ip of the comments api so nginx can forward to it
ARG COMMENTS_BACKEND
ENV COMMENTS_BACKEND=${WITH_BACKEND}
RUN ["hugo", "--minify"]
FROM python:3.11-alpine as fiddling
RUN ["mkdir", "/application"]
RUN ["adduser", "-D", "-h", "/application", "application"]
# might need to chown these
ADD ./scripts/template_convert.py /application/template_convert.py
ADD ./nginx.conf.template /application/nginx.conf.template
WORKDIR /application
USER application
RUN ["python", "/application/template_convert.py"]
FROM nginx:1.25-alpine
COPY --from=fiddling /application/nginx.conf /etc/nginx/nginx.conf
COPY --from=build /root/public /usr/share/nginx/html

View file

@ -29,3 +29,8 @@ theme = "liquorice"
[markup.goldmark]
[markup.goldmark.renderer]
unsafe = true
[security]
[security.funcs]
# first 2 vars are things hugo has built in and I'm keeping to avoid breakage
getenv = ['^HUGO_', '^CI$', "COMMENTS_BACKEND"]

43
content/blog/blog_v2.md Normal file
View file

@ -0,0 +1,43 @@
---
title: "Who needs a CMS anyways? (and also redeploying to docker)"
description: ""
date: 2023-09-08
draft: true
---
# What's up?
We're adding comments to this blog and setting it up to deploy via docker.
## Why?
Because I wanted to add comments. The way I'm planning on doing that will mean that this blog will be more complex. Specifically in addition to generating static files and having nginx serve them I'll need to have a separate service. That separate service (and the database it depends on) will be contained within a docker container for convenience. But with parts of the site being deployed via docker I might as well deploy all of them via docker.
### Sounds like you've written a CMS so why is the static file hosting not a part of that?
Because I'm not writing a CMS, I'm just writing the backend for comments and sticking some htmx stuff into the hugo template for a blog for the frontend.
## [Writing the Go backend]
### Why Go?
### Annoyances
- Doesn't handle html multipart forms correctly(or the browser is wrong but I doubt that)
- Magic redirect when there's no trailing /
### Anyways
- yeeted oauth midway through
## [Writing the Hugo templating frontend]
## [Setting up the docker Containers]
## [Changing github actions and deployment pipeline to rebuild the docker container]
## [Conclusion]

View file

@ -37,6 +37,7 @@
</div>
{{ partial "author.html" .}}
{{ partial "comments.html" . }}
<div class="row li-pagination">
<div class="eight columns">
<div class="li-pagination-previous">

View file

@ -0,0 +1,6 @@
<noscript>
you need to enable javascript to view comments(or be a wizard)
</noscript>
{{ cond (not (eq (os.Getenv "COMMENTS_BACKEND") "")) (safeHTML (printf "<div hx-get='/comments/%s' hx-target='this' hx-trigger='load' hx-swap='outerHTML'></div>" .File.Path)) ""}}

View file

@ -9,6 +9,8 @@
<link rel="stylesheet" href="{{ .Site.BaseURL }}/libraries/normalize.3.0.1.css" />
<link rel="stylesheet" href="{{ .Site.BaseURL }}/css/liquorice.css" />
{{ cond (eq .Page.Kind "page") (safeHTML (printf "<link rel='stylesheet' href='%s/css/single.css'>" .Site.BaseURL)) "" }}
<script src="https://unpkg.com/htmx.org@1.9.5" integrity="sha384-xcuj3WpfgjlKF+FXhSQFQ0ZNr39ln+hwjN3npfM9VBnUskLolQAcN80McRIVOPuO" crossorigin="anonymous"></script>
<script src="https://unpkg.com/htmx.org/dist/ext/json-enc.js"></script>
<link rel="icon" href="{{ .Site.BaseURL }}/img/icon.png" />
<meta property="og:title" content="{{ .Title }}"/>
<meta property="og:type" content="website"/>

29
nginx.conf.template Normal file
View file

@ -0,0 +1,29 @@
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name pagwin.xyz;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
# weird comments around this block is so we can easily yeet it if the comments backend isn't present
###{---
location /comments {
# we're going to use a python program to substitute this out
proxy_pass http://${{COMMENTS_BACKEND}}
}
###---}
}
}

20
scripts/template_convert.py Executable file
View file

@ -0,0 +1,20 @@
#!/bin/env python3
import os
import re
var_name = "COMMENTS_BACKEND"
file_name = "nginx.conf"
back = os.environ.get(var_name)
buf = str()
with open(file_name+".template") as file:
buf = file.read()
if back == None:
buf = re.sub("###{---(.|\n)*###---}", "", buf)
else:
# ${{\s*$var_name\s*}}
buf = re.sub(rf"\${{{{\s*{var_name}\s*}}}}",var_name,buf)
with open(file_name, "w+") as file:
file.write(buf)