Skip to content

Commit 1c243a6

Browse files
committed
attempt to use earthly
Signed-off-by: Xe Iaso <[email protected]>
1 parent 902efdf commit 1c243a6

File tree

5 files changed

+131
-58
lines changed

5 files changed

+131
-58
lines changed

.github/workflows/earthly.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
# Publish semver tags as releases.
7+
tags: [ 'v*.*.*' ]
8+
pull_request:
9+
branches: [ "main" ]
10+
env:
11+
# Use docker.io for Docker Hub if empty
12+
REGISTRY: ghcr.io
13+
# github.repository as <account>/<repo>
14+
IMAGE_NAME: ${{ github.repository }}
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
packages: write
22+
# This is used to complete the identity challenge
23+
# with sigstore/fulcio when running outside of PRs.
24+
id-token: write
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
- uses: earthly/actions-setup@v1
30+
with:
31+
github-token: ${{ secrets.GITHUB_TOKEN }}
32+
version: "latest" # or pin to an specific version, e.g. "0.8.1"
33+
# Login against a Docker registry except on PR
34+
# https://github.com/docker/login-action
35+
- name: Log into registry ${{ env.REGISTRY }}
36+
if: github.event_name != 'pull_request'
37+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
38+
with:
39+
registry: ${{ env.REGISTRY }}
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
# Extract metadata (tags, labels) for Docker
43+
# https://github.com/docker/metadata-action
44+
- name: Extract Docker metadata
45+
id: meta
46+
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
47+
with:
48+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
49+
# Build and push Docker image with Buildx (don't push on PR)
50+
# https://github.com/docker/build-push-action
51+
- name: Build and push Docker image
52+
id: steps.build-and-push
53+
run: |
54+
earthly --push +xesite
55+
earthly --push +patreon-saasproxy

.github/workflows/main.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

Earthfile

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
VERSION 0.8
2+
FROM alpine:edge
3+
WORKDIR /app
4+
5+
deps:
6+
FROM golang:1.22-alpine
7+
WORKDIR /app
8+
9+
COPY go.mod go.sum ./
10+
RUN go mod download
11+
12+
SAVE ARTIFACT go.mod
13+
14+
fonts:
15+
FROM alpine:edge
16+
WORKDIR /fonts
17+
RUN apk add -U unzip ca-certificates curl \
18+
&& curl -Lo iosevka.zip https://cdn.xeiaso.net/static/pkg/iosevka/ttf.zip \
19+
&& unzip -d /fonts iosevka.zip
20+
21+
SAVE ARTIFACT /fonts/ttf
22+
23+
dhall-json:
24+
FROM alpine:edge
25+
RUN apk add -U curl bzip2 ca-certificates \
26+
&& curl -L -o dhall-linux.tar.bz2 https://github.com/dhall-lang/dhall-haskell/releases/download/1.42.0/dhall-json-1.7.12-x86_64-linux.tar.bz2 \
27+
&& tar -xvjf dhall-linux.tar.bz2 \
28+
&& mv bin/dhall-to-json .
29+
30+
SAVE ARTIFACT dhall-to-json
31+
32+
build-patreon-saasproxy:
33+
FROM +deps
34+
COPY . .
35+
36+
RUN --mount=type=cache,target=/root/.cache CGO_ENABLED=0 go build -gcflags "all=-N -l" -o patreon-saasproxy ./cmd/patreon-saasproxy
37+
38+
SAVE ARTIFACT patreon-saasproxy
39+
40+
patreon-saasproxy:
41+
FROM alpine:edge
42+
WORKDIR /app
43+
44+
COPY +build-patreon-saasproxy/patreon-saasproxy /app/patreon-saasproxy
45+
46+
RUN apk add -U ca-certificates
47+
48+
CMD ["./patreon-saasproxy"]
49+
50+
SAVE IMAGE ghcr.io/xe/site/patreon-saasproxy:earthly
51+
52+
build-xesite:
53+
FROM +deps
54+
COPY . .
55+
56+
RUN --mount=type=cache,target=/root/.cache CGO_ENABLED=0 go build -gcflags "all=-N -l" -o xesite ./cmd/xesite
57+
58+
SAVE ARTIFACT xesite
59+
60+
xesite:
61+
FROM alpine:edge
62+
WORKDIR /app
63+
64+
COPY +build-xesite/xesite /app/xesite
65+
COPY +fonts/ttf /app/fonts
66+
COPY +dhall-json/dhall-to-json /usr/local/bin/dhall-to-json
67+
68+
RUN apk add -U ca-certificates deno typst
69+
ENV TYPST_FONT_PATHS=/app/fonts
70+
71+
CMD ["./xesite"]
72+
73+
SAVE IMAGE ghcr.io/xe/site/bin:earthly

flake.nix

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -108,38 +108,6 @@
108108
subPackages = [ "cmd/patreon-saasproxy" ];
109109
};
110110

111-
iosevka = pkgs.stdenvNoCC.mkDerivation {
112-
name = "xesite-iosevka";
113-
buildInputs = with pkgs; [
114-
python311Packages.brotli
115-
python311Packages.fonttools
116-
];
117-
dontUnpack = true;
118-
buildPhase = ''
119-
mkdir -p out
120-
${pkgs.unzip}/bin/unzip ${
121-
self.inputs.iosevka.packages.${system}.default
122-
}/ttf.zip
123-
for ttf in ttf/*.ttf; do
124-
cp $ttf out
125-
name=`basename -s .ttf $ttf`
126-
pyftsubset \
127-
$ttf \
128-
--output-file=out/"$name".woff2 \
129-
--flavor=woff2 \
130-
--layout-features=* \
131-
--no-hinting \
132-
--desubroutinize \
133-
--unicodes="U+0000-0170,U+00D7,U+00F7,U+2000-206F,U+2074,U+20AC,U+2122,U+2190-21BB,U+2212,U+2215,U+F8FF,U+FEFF,U+FFFD,U+00E8"
134-
done
135-
136-
'';
137-
installPhase = ''
138-
mkdir -p $out/static/css/iosevka
139-
cp out/* $out/static/css/iosevka
140-
'';
141-
};
142-
143111
docker = pkgs.dockerTools.buildLayeredImage {
144112
name = "ghcr.io/xe/site/bin";
145113
tag = "latest";

lume/src/talks/2024/nix-docker-build.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ title: Nix is a better Docker image builder than Docker's image builder
33
date: 2024-03-15
44
year: 2024
55
image: talks/2024/nix-docker-builder/001
6+
tags:
7+
- nix
8+
- nixos
69
---
710

811
export const ThreeColumnLayout = ({ children }) => {

0 commit comments

Comments
 (0)