Build more images

This commit is contained in:
razonyang 2023-03-12 15:21:05 +08:00
parent 7c11404e4e
commit 6fd14e64eb
19 changed files with 202 additions and 56 deletions

View file

@ -1,46 +1,128 @@
name: Check and Build Latest Image
name: check and build latest image
on:
schedule:
- cron: '*/30 * * * *'
issue_comment:
types: [created]
workflow_dispatch:
push:
jobs:
check:
build-and-push-image:
strategy:
fail-fast: false
matrix:
version: ['', 'reg-']
prefix: ['', 'base-', 'go-', 'node-', 'exts-']
include:
- version: ''
gcc: true
extended: true
- version: ''
prefix: ''
dockerfile: docker/default/Dockerfile
tags: razonyang/hugo:latest,razonyang/hugo:{0}
- version: 'reg-'
prefix: ''
dockerfile: docker/default/Dockerfile
tags: razonyang/hugo:reg,razonyang/hugo:reg-{0}
- prefix: base-
dockerfile: docker/base/Dockerfile
tags: razonyang/hugo:{1}base,razonyang/hugo:{2}base-{0}
- prefix: go-
dockerfile: docker/go/Dockerfile
tags: razonyang/hugo:{1}go,razonyang/hugo:{2}go-{0}
- prefix: node-
dockerfile: docker/node/Dockerfile
tags: razonyang/hugo:{1}node,razonyang/hugo:{2}node-{0}
- prefix: exts-
dockerfile: docker/exts/Dockerfile
tags: razonyang/hugo:{1}exts,razonyang/hugo:{2}exts-{0}
runs-on: ubuntu-latest
if: ${{ github.event_name == 'schedule' || github.event.issue.number == 3 }}
outputs:
version: ${{ steps.hugo.outputs.version }}
exists: ${{ steps.check.outputs.exists }}
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event_name == 'push' || github.event.issue.number == 3 }}
steps:
-
id: hugo
name: Fetch latest Hugo release
- name: Fetch latest Hugo release
id: release
run: curl https://api.github.com/repos/gohugoio/hugo/releases/latest -s | jq .tag_name -r | awk '{print "version="substr($1,2)}' >> $GITHUB_OUTPUT
-
- name: Check if the base image exists
if: steps.release.outputs.version != 'ull'
id: check
run: curl https://hub.docker.com/v2/namespaces/razonyang/repositories/hugo/tags/${{steps.hugo.outputs.version}} -s | jq 'has("name")' | awk '{print "exists="$1}' >> $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
needs: check
if: ${{ ((needs.check.outputs.version != 'ull') && (needs.check.outputs.exists == 'false')) }}
steps:
-
name: Set up QEMU
run: curl https://hub.docker.com/v2/namespaces/razonyang/repositories/hugo/tags/${{ matrix.version }}${{ matrix.prefix }}${{ steps.release.outputs.version }} -s | jq 'has("name")' | awk '{print "exists="$1}' >> $GITHUB_OUTPUT
- name: Checkout repository
if: steps.check.outputs.exists == 'false'
uses: actions/checkout@v3
- name: Set up QEMU
if: steps.check.outputs.exists == 'false'
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
- name: Set up Docker Buildx
if: steps.check.outputs.exists == 'false'
uses: docker/setup-buildx-action@v2
-
name: Login to Docker Hub
with:
driver: docker
- name: Login to Docker Hub
if: steps.check.outputs.exists == 'false'
uses: docker/login-action@v2
with:
username: razonyang
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v3
- name: Build the Alpine image
if: steps.check.outputs.exists == 'false'
uses: docker/build-push-action@v4
with:
context: ./docker/alpine
file: ./docker/alpine/Dockerfile
load: true
tags: hugo-alpine:latest
build-args: |
GCC=${{ matrix.gcc }}
- name: Build the builder image
if: steps.check.outputs.exists == 'false'
uses: docker/build-push-action@v4
with:
context: ./docker/builder
file: ./docker/builder/Dockerfile
load: true
tags: hugo-builder:latest
build-args: |
HUGO_VERSION=v${{ steps.release.outputs.version }}
HUGO_EXTENDED=${{ matrix.extended }}
- name: Build and export to Docker
if: steps.check.outputs.exists == 'false'
uses: docker/build-push-action@v4
with:
load: true
context: .
file: ${{ matrix.dockerfile }}
tags: razonyang/hugo:${{ matrix.version }}${{ matrix.prefix }}test
build-args: |
GCC=${{ matrix.gcc }}
build-contexts: |
alpine=docker-image://hugo-alpine:latest
builder=docker-image://hugo-builder:latest
- name: Test
if: steps.check.outputs.exists == 'false'
run: |
docker run --rm -v $PWD/site:/src razonyang/hugo:${{ matrix.version }}${{ matrix.prefix }}test hugo
- name: Build and push
if: steps.check.outputs.exists == 'false'
uses: docker/build-push-action@v4
with:
push: true
tags: razonyang/hugo:latest,razonyang/hugo:${{ needs.check.outputs.version }}
context: .
file: ${{ matrix.dockerfile }}
tags: ${{ format(matrix.tags, steps.release.outputs.version, matrix.version, matrix.version) }}
build-args: |
HUGO_VERSION=v${{ needs.check.outputs.version }}
GCC=${{ matrix.gcc }}
build-contexts: |
alpine=docker-image://hugo-alpine:latest
builder=docker-image://hugo-builder:latest

View file

@ -1,29 +0,0 @@
ARG GOPROXY=
ARG HUGO_VERSION=latest
ARG NODE_VERSION=19
FROM golang:alpine as golang
ARG HUGO_VERSION
ARG GOPROXY
# Go module proxy
ENV GOPROXY=${GOPROXY}
RUN apk add --no-cache build-base
# Install Hugo
RUN go install -tags extended github.com/gohugoio/hugo@${HUGO_VERSION}
FROM node:${NODE_VERSION}-alpine as node
# Copy Go and Hugo.
COPY --from=golang /usr/local/go /usr/local/go
COPY --from=golang /go/bin/hugo /usr/local/bin/hugo
RUN ln -s /usr/local/go/bin/go /usr/local/bin/go
RUN apk add --no-cache git
# Working directory.
WORKDIR /src
# Build the site.
CMD hugo --minify --gc --enableGitInfo

4
docker/alpine/Dockerfile Normal file
View file

@ -0,0 +1,4 @@
FROM alpine
ARG GCC
RUN apk add --no-cache ca-certificates
RUN if [[ -n "$GCC" ]]; then apk add --no-cache gcc; fi

5
docker/base/Dockerfile Normal file
View file

@ -0,0 +1,5 @@
# syntax=docker/dockerfile:1
FROM alpine
COPY --from=builder /go/bin/hugo /usr/bin/hugo
WORKDIR /src
CMD hugo env

View file

@ -0,0 +1,5 @@
FROM golang:alpine
ARG HUGO_VERSION=latest
ARG HUGO_EXTENDED=
RUN apk add --no-cache gcc g++ musl-dev
RUN if [[ -z "$HUGO_EXTENDED" ]]; then go install github.com/gohugoio/hugo@${HUGO_VERSION}; else go install -tags extended github.com/gohugoio/hugo@${HUGO_VERSION}; fi

View file

@ -0,0 +1,8 @@
# syntax=docker/dockerfile:1
FROM node:alpine as node
COPY --from=builder /usr/local/go /usr/local/go
RUN ln -s /usr/local/go/bin/go /usr/local/bin/go
COPY --from=builder /go/bin/hugo /usr/local/bin/hugo
RUN apk add --no-cache git
WORKDIR /src
CMD hugo env

9
docker/exts/Dockerfile Normal file
View file

@ -0,0 +1,9 @@
# syntax=docker/dockerfile:1
FROM node:alpine as node
COPY --from=builder /usr/local/go /usr/local/go
RUN ln -s /usr/local/go/bin/go /usr/local/bin/go
COPY --from=builder /go/bin/hugo /usr/local/bin/hugo
RUN apk add --no-cache git
RUN npm i -g postcss-cli autoprefixer @fullhuman/postcss-purgecss rtlcss
WORKDIR /src
CMD hugo env

8
docker/go/Dockerfile Normal file
View file

@ -0,0 +1,8 @@
# syntax=docker/dockerfile:1
FROM golang:alpine
ARG GCC
RUN apk add --no-cache ca-certificates
RUN if [[ -n "$GCC" ]]; then apk add --no-cache gcc; fi
COPY --from=builder /go/bin/hugo /usr/local/bin/hugo
WORKDIR /src
CMD hugo env

8
docker/node/Dockerfile Normal file
View file

@ -0,0 +1,8 @@
# syntax=docker/dockerfile:1
FROM node:alpine
ARG GCC
RUN apk add --no-cache ca-certificates
RUN if [[ -n "$GCC" ]]; then apk add --no-cache gcc; fi
COPY --from=builder /go/bin/hugo /usr/local/bin/hugo
WORKDIR /src
CMD hugo env

0
site/.hugo_build.lock Normal file
View file

3
site/config.toml Normal file
View file

@ -0,0 +1,3 @@
baseURL = 'http://example.org/'
languageCode = 'en-us'
title = 'Hugo Example Site'

3
site/content/_index.md Normal file
View file

@ -0,0 +1,3 @@
---
title: Home
---

View file

@ -0,0 +1,5 @@
---
title: Bar
---
Hi, I am bar.

View file

@ -0,0 +1,5 @@
---
title: Foo
---
Hi, I am Foo.

View file

@ -0,0 +1,9 @@
<html>
<head>
<title>{{ .Page.Title }}</title>
{{ partial "get-remote" . }}
</head>
<body>
{{ block "main" . }}{{ end }}
</body>
</html>

View file

@ -0,0 +1,3 @@
{{ define "main" }}
{{ .Content }}
{{ end }}

View file

@ -0,0 +1,4 @@
{{ define "main" }}
<h1>{{ .Title }}</h1>
<div>{{ .Content }}</div>
{{ end }}

9
site/layouts/index.html Normal file
View file

@ -0,0 +1,9 @@
{{ define "main" }}
<ul>
{{ range .Site.RegularPages }}
<li>
<a href="{{ .RelPermalink }}">{{ .Title }}</a>
</li>
{{ end }}
</ul>
{{ end }}

View file

@ -0,0 +1,5 @@
{{ $api := "https://api.github.com" }}
{{ $resp := resources.GetRemote $api }}
{{ if not $resp }}
{{ errorf "failed to get remote: %s" $api }}
{{ end }}