Skip to content

Commit

Permalink
Add Docker + GHA builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Firefishy committed Sep 17, 2024
1 parent 1437888 commit 71c2a1c
Show file tree
Hide file tree
Showing 8 changed files with 336 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ignore git metadata folder
.git/
.github/

# Ignore docker related files
Dockerfile*
docker-compose.*
.dockerignore
.gitignore
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# EditorConfig is awesome: https://EditorConfig.org

root = true

[*]
charset = utf-8
indent_style = space
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
indent_size = 2
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
67 changes: 67 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: ci

on:
push:
branches:
- '**'
- '!dependabot/**'
tags:
- 'v*.*.*'
pull_request:
branches:
- 'master'
- 'main'
- 'gh-pages'
schedule:
- cron: '25 3 */7 * *'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-{{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest,enable={{is_default_branch}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM docker.io/debian:12 AS build

COPY . /app/_site

RUN find /app/_site/ -type f \( -name "*.html" -o -name "*.css" -o -name "*.js" -o -name "*.xml" -o -name "*.json" -o -name "*.svg" -o -name "*.ttf" -o -name "*.woff2" -o -name "*.woff" -o -name "*.eot" -o -name "*.otf" \) -print0 | xargs -0 -P4 --no-run-if-empty gzip -9k

# https://github.com/nginxinc/docker-nginx-unprivileged
FROM ghcr.io/nginxinc/nginx-unprivileged:stable-alpine AS webserver

RUN echo "absolute_redirect off;" >/etc/nginx/conf.d/no-absolute_redirect.conf
RUN echo "gzip_static on; gzip_proxied any;" >/etc/nginx/conf.d/gzip_static.conf
# brotli_static not yet available in standard nginx distribution
# RUN echo "brotli_static on; brotli_proxied any;" >/etc/nginx/conf.d/brotli_static.conf

# Copy built site from build stage
COPY --from=build /app/_site /usr/share/nginx/html

# Test configuration during docker build
RUN nginx -t

# Port the container will listen on
EXPOSE 8080
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:

app:
build:
context: .
dockerfile: Dockerfile
ports:
- 8080:8080
99 changes: 99 additions & 0 deletions wp-sitemap-index.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
exclude-result-prefixes="sitemap"
>

<xsl:output method="html" encoding="UTF-8" indent="yes" />

<!--
Set variables for whether lastmod occurs for any sitemap in the index.
We do this up front because it can be expensive in a large sitemap.
-->
<xsl:variable name="has-lastmod" select="count( /sitemap:sitemapindex/sitemap:sitemap/sitemap:lastmod )" />

<xsl:template match="/">
<html lang="en-US">
<head>
<title>XML Sitemap</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
color: #444;
}

#sitemap {
max-width: 980px;
margin: 0 auto;
}

#sitemap__table {
width: 100%;
border: solid 1px #ccc;
border-collapse: collapse;
}

#sitemap__table tr td.loc {
/*
* URLs should always be LTR.
* See https://core.trac.wordpress.org/ticket/16834
* and https://core.trac.wordpress.org/ticket/49949
*/
direction: ltr;
}

#sitemap__table tr th {
text-align: left;
}

#sitemap__table tr td,
#sitemap__table tr th {
padding: 10px;
}

#sitemap__table tr:nth-child(odd) td {
background-color: #eee;
}

a:hover {
text-decoration: none;
}

</style>
</head>
<body>
<div id="sitemap">
<div id="sitemap__header">
<h1>XML Sitemap</h1>
<p><a href="https://www.sitemaps.org/">Learn more about XML sitemaps.</a></p>
</div>
<div id="sitemap__content">
<p class="text">Number of URLs in this XML Sitemap: <xsl:value-of select="count( sitemap:sitemapindex/sitemap:sitemap )" />.</p>
<table id="sitemap__table">
<thead>
<tr>
<th class="loc">URL</th>
<xsl:if test="$has-lastmod">
<th class="lastmod">Last Modified</th>
</xsl:if>
</tr>
</thead>
<tbody>
<xsl:for-each select="sitemap:sitemapindex/sitemap:sitemap">
<tr>
<td class="loc"><a href="{sitemap:loc}"><xsl:value-of select="sitemap:loc" /></a></td>
<xsl:if test="$has-lastmod">
<td class="lastmod"><xsl:value-of select="sitemap:lastmod" /></td>
</xsl:if>
</tr>
</xsl:for-each>
</tbody>
</table>
</div>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
114 changes: 114 additions & 0 deletions wp-sitemap.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
exclude-result-prefixes="sitemap"
>

<xsl:output method="html" encoding="UTF-8" indent="yes" />

<!--
Set variables for whether lastmod, changefreq or priority occur for any url in the sitemap.
We do this up front because it can be expensive in a large sitemap.
-->
<xsl:variable name="has-lastmod" select="count( /sitemap:urlset/sitemap:url/sitemap:lastmod )" />
<xsl:variable name="has-changefreq" select="count( /sitemap:urlset/sitemap:url/sitemap:changefreq )" />
<xsl:variable name="has-priority" select="count( /sitemap:urlset/sitemap:url/sitemap:priority )" />

<xsl:template match="/">
<html lang="en-US">
<head>
<title>XML Sitemap</title>
<style>

body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
color: #444;
}

#sitemap {
max-width: 980px;
margin: 0 auto;
}

#sitemap__table {
width: 100%;
border: solid 1px #ccc;
border-collapse: collapse;
}

#sitemap__table tr td.loc {
/*
* URLs should always be LTR.
* See https://core.trac.wordpress.org/ticket/16834
* and https://core.trac.wordpress.org/ticket/49949
*/
direction: ltr;
}

#sitemap__table tr th {
text-align: left;
}

#sitemap__table tr td,
#sitemap__table tr th {
padding: 10px;
}

#sitemap__table tr:nth-child(odd) td {
background-color: #eee;
}

a:hover {
text-decoration: none;
}

</style>
</head>
<body>
<div id="sitemap">
<div id="sitemap__header">
<h1>XML Sitemap</h1>
<p><a href="https://www.sitemaps.org/">Learn more about XML sitemaps.</a></p>
</div>
<div id="sitemap__content">
<p class="text">Number of URLs in this XML Sitemap: <xsl:value-of select="count( sitemap:urlset/sitemap:url )" />.</p>
<table id="sitemap__table">
<thead>
<tr>
<th class="loc">URL</th>
<xsl:if test="$has-lastmod">
<th class="lastmod">Last Modified</th>
</xsl:if>
<xsl:if test="$has-changefreq">
<th class="changefreq">Change Frequency</th>
</xsl:if>
<xsl:if test="$has-priority">
<th class="priority">Priority</th>
</xsl:if>
</tr>
</thead>
<tbody>
<xsl:for-each select="sitemap:urlset/sitemap:url">
<tr>
<td class="loc"><a href="{sitemap:loc}"><xsl:value-of select="sitemap:loc" /></a></td>
<xsl:if test="$has-lastmod">
<td class="lastmod"><xsl:value-of select="sitemap:lastmod" /></td>
</xsl:if>
<xsl:if test="$has-changefreq">
<td class="changefreq"><xsl:value-of select="sitemap:changefreq" /></td>
</xsl:if>
<xsl:if test="$has-priority">
<td class="priority"><xsl:value-of select="sitemap:priority" /></td>
</xsl:if>
</tr>
</xsl:for-each>
</tbody>
</table>
</div>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

0 comments on commit 71c2a1c

Please sign in to comment.