Skip to content

Commit 9674917

Browse files
authored
Merge pull request #293: Dockerfiles from templates
Dockerfiles from templates
2 parents 6c61a2a + b520f71 commit 9674917

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2005
-817
lines changed

.github/actions/build/action.yaml

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ inputs:
1414
description: "Pandoc version to build."
1515
default: main
1616
type: string
17-
dockerfile:
18-
description: "Dockerfile to build"
19-
required: true
20-
type: string
17+
no_cache:
18+
description: "Don't use the cache when building"
19+
default: false
20+
type: boolean
2121
target:
2222
description: "Dockerfile target"
2323
type: string
@@ -32,63 +32,50 @@ runs:
3232
- name: Env variables
3333
shell: bash
3434
run: |
35-
if [ "${{ inputs.pandoc_version }}" = 'edge' ]; then
36-
printf 'PANDOC_COMMIT=main\n' >> $GITHUB_ENV
37-
else
38-
printf 'PANDOC_COMMIT=${{inputs.pandoc_version}}\n' >> $GITHUB_ENV
39-
fi
40-
TEST_IMAGE=${{
35+
printf 'TEST_IMAGE=%s\n' ${{
4136
format('pandoc/test:{0}-{1}-{2}',
4237
inputs.image_type,
4338
inputs.base_system,
4439
inputs.pandoc_version
45-
) }}
46-
printf 'TEST_IMAGE<<EOF\n%s\nEOF\n' "$TEST_IMAGE" >> $GITHUB_ENV
47-
48-
- name: Meta
49-
id: meta
50-
uses: ./.github/actions/meta
51-
with:
52-
images: |
53-
pandoc/${{ inputs.image_type }}
54-
ghcr.io/pandoc/${{ inputs.image_type }}
55-
pandoc_version: ${{ env.PANDOC_COMMIT }}
56-
build_stack: ${{ inputs.base_system }}
40+
) }} >> $GITHUB_ENV
5741
5842
- name: Build
5943
if: >-
6044
${{ inputs.build_stack != 'static' || inputs.image_type == 'minimal' }}
61-
uses: docker/build-push-action@v6
45+
uses: docker/bake-action@v6
6246
with:
63-
context: '.'
64-
file: ${{ inputs.dockerfile }}
47+
files: docker-bake.json
6548
load: true
49+
no-cache: ${{ inputs.no_cache }}
6650
pull: true
6751
push: false
68-
target: ${{ inputs.target }}
69-
tags: ${{ env.TEST_IMAGE }}
70-
build-args: ${{ steps.meta.outputs.build_args }}
52+
set: |
53+
*.platform=linux/amd64
54+
*.tags=${{ env.TEST_IMAGE }}
55+
source: '.'
56+
targets: ${{ inputs.base_system }}-${{ inputs.image_type }}
57+
workdir: ${{ inputs.pandoc_version }}
7158

7259
- name: Test
7360
shell: bash
7461
run: make test-${{ inputs.image_type }} IMAGE=${{ env.TEST_IMAGE }}
7562

76-
- name: Push
63+
- name: Build arm64 and push
7764
if: >-
7865
${{ inputs.build_stack != 'static' || inputs.image_type == 'minimal' }}
79-
uses: docker/build-push-action@v6
66+
uses: docker/bake-action@v6
8067
with:
81-
context: '.'
82-
file: ${{ inputs.dockerfile }}
83-
labels: ${{ steps.meta.outputs.labels }}
68+
files: docker-bake.json
69+
no-cache: ${{ inputs.no_cache }}
8470
pull: true
8571
push: true
86-
target: ${{ inputs.target }}
87-
tags: ${{ steps.meta.outputs.tags }}
88-
build-args: ${{ steps.meta.outputs.build_args }}
8972
# LaTeX doesn't work for Alpine on arm64.
90-
platforms: ${{
91-
( inputs.base_system == 'alpine' &&
92-
(inputs.image_type == 'latex' || inputs.image_type == 'extra') )
93-
&& 'linux/amd64'
94-
|| 'linux/amd64,linux/arm64' }}
73+
set: |
74+
*.platform=${{
75+
( inputs.base_system == 'alpine' &&
76+
(inputs.image_type == 'latex' || inputs.image_type == 'extra') )
77+
&& 'linux/amd64'
78+
|| 'linux/amd64,linux/arm64' }}
79+
source: '.'
80+
targets: ${{ inputs.base_system }}-${{ inputs.image_type }}
81+
workdir: ${{ inputs.pandoc_version }}

.github/workflows/addon.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ on:
1212
base_system:
1313
type: string
1414
default: alpine
15+
no_cache:
16+
type: boolean
17+
default: false
1518
secrets:
1619
DOCKER_HUB_USERNAME:
1720
required: true
@@ -37,6 +40,9 @@ on:
3740
- alpine
3841
- ubuntu
3942
default: alpine
43+
no_cache:
44+
type: boolean
45+
default: false
4046

4147
jobs:
4248
build:
@@ -47,6 +53,16 @@ jobs:
4753
- name: Checkout
4854
uses: actions/checkout@v4
4955

56+
- name: Install current pandoc
57+
uses: pandoc/actions/setup@v1
58+
59+
- name: Generate Dockerfiles
60+
run: >-
61+
pandoc lua pandock.lua generate \
62+
${{ inputs.pandoc_version }} \
63+
${{ inputs.base_system }} \
64+
${{ inputs.addon }}
65+
5066
- name: Login to Docker Hub
5167
uses: docker/login-action@v3
5268
with:
@@ -73,4 +89,4 @@ jobs:
7389
image_type: ${{ inputs.addon }}
7490
base_system: ${{ inputs.base_system }}
7591
pandoc_version: ${{ inputs.pandoc_version }}
76-
dockerfile: ${{ inputs.base_system }}/${{ inputs.addon }}/Dockerfile
92+
no_cache: ${{ inputs.no_cache }}

.github/workflows/build.yaml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ on:
1212
inputs:
1313
pandoc_version:
1414
description: >-
15-
Pandoc version; must be either `main` or a release number
16-
default: main
15+
Version; must be either `edge` or the number of a pandoc release
16+
default: edge
1717
type: string
1818
base_system:
1919
description: Docker base system
@@ -75,7 +75,19 @@ jobs:
7575
fail-fast: false
7676

7777
steps:
78-
- uses: actions/checkout@v4
78+
- name: Checkout
79+
uses: actions/checkout@v4
80+
81+
- name: Install current pandoc
82+
uses: pandoc/actions/setup@v1
83+
84+
- name: Generate Dockerfiles
85+
run: >-
86+
pandoc lua pandock.lua generate \
87+
${{ inputs.pandoc_version }} \
88+
${{ inputs.base_system }} \
89+
${{ inputs.addon }}
90+
7991
8092
- name: Login to Docker Hub
8193
uses: docker/login-action@v3
@@ -104,8 +116,7 @@ jobs:
104116
image_type: minimal
105117
base_system: ${{ matrix.stack }}
106118
pandoc_version: ${{ matrix.version }}
107-
dockerfile: ${{ matrix.stack }}/Dockerfile
108-
target: ${{ matrix.stack }}-minimal
119+
target: minimal
109120

110121
- name: core
111122
uses: ./.github/actions/build
@@ -114,8 +125,7 @@ jobs:
114125
image_type: core
115126
base_system: ${{ matrix.stack }}
116127
pandoc_version: ${{ matrix.version }}
117-
dockerfile: ${{ matrix.stack }}/Dockerfile
118-
target: ${{ matrix.stack }}-core
128+
target: core
119129

120130
typst:
121131
name: Typst (${{ matrix.stack }})

.github/workflows/dockerhub-description.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ jobs:
3333
- name: Short description
3434
id: config
3535
run: |
36-
printf 'short_description=%s\n' \
37-
"$(pandoc lua docs/scripts/short-description.lua \
38-
${{ matrix.image }})" \
36+
pandoc lua pandock.lua short-description "${{ matrix.image }})" \
3937
>> $GITHUB_OUTPUT
4038
4139
Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Base ##################################################################
2-
ARG base_image_version=3.20
3-
FROM alpine:$base_image_version AS alpine-builder-base
2+
ARG base_image_version=${base_image_version}
3+
FROM alpine:$$base_image_version AS builder-base
44
WORKDIR /app
55

6+
# We're already very specific about the version of the alpine image, so
7+
# it seems reasonable not to require specific package versions.
8+
#
9+
# hadolint ignore=DL3018
610
RUN apk --no-cache add \
711
alpine-sdk \
812
bash \
@@ -21,40 +25,37 @@ RUN apk --no-cache add \
2125

2226
# Setup and configure cabal
2327
ENV CABAL_CONFIG=/root/.config/cabal/config
24-
COPY cabal.root.config $CABAL_CONFIG
2528

26-
RUN cabal --version \
29+
RUN cabal user-config init \
30+
&& cabal --version \
2731
&& ghc --version \
2832
&& cabal update
2933

3034
# Builder ###############################################################
31-
FROM alpine-builder-base AS alpine-builder
32-
ARG pandoc_commit=main
33-
RUN git clone --branch=$pandoc_commit --depth=1 --quiet \
34-
https://github.com/jgm/pandoc /usr/src/pandoc
35+
FROM builder-base AS builder
36+
RUN git clone --branch=${pandoc_commit} --depth=1 --quiet \
37+
https://github.com/jgm/pandoc /app
3538

36-
COPY ./alpine/freeze/pandoc-$pandoc_commit.project.freeze \
37-
/usr/src/pandoc/cabal.project.freeze
38-
39-
# Install Haskell dependencies
40-
WORKDIR /usr/src/pandoc
4139
# Add pandoc-crossref to project
42-
ARG without_crossref=
43-
RUN test -n "$without_crossref" || \
44-
printf "extra-packages: pandoc-crossref\n" > cabal.project.local;
45-
46-
# Additional projects to compile alongside pandoc
47-
ARG extra_packages="pandoc-cli pandoc-crossref"
40+
RUN printf "extra-packages: pandoc-crossref\n" > cabal.project.local;
4841

4942
# Build pandoc and pandoc-crossref. The `allow-newer` is required for
5043
# when pandoc-crossref has not been updated yet, but we want to build
5144
# anyway.
52-
RUN cabal update && cabal build \
53-
--allow-newer 'lib:pandoc' \
54-
--disable-tests \
55-
--disable-bench \
56-
--jobs \
57-
. $extra_packages
45+
RUN cabal build \
46+
--jobs \
47+
--disable-tests \
48+
--disable-bench \
49+
--enable-split-sections \
50+
--enable-executable-stripping \
51+
--upgrade-dependencies \
52+
--allow-newer='lib:pandoc' \
53+
--ghc-options='-O1 -optc-Os -optl=-pthread -fPIC -j' \
54+
--ghc-options='+RTS -M4G -A128m -n2m -RTS' \
55+
$for(cabal.constraints)$
56+
--constraint='${it}' \
57+
$endfor$
58+
. pandoc-cli pandoc-crossref
5859

5960
# Cabal's exec stripping doesn't seem to work reliably, let's do it here.
6061
RUN find dist-newstyle \
@@ -63,12 +64,12 @@ RUN find dist-newstyle \
6364
-exec cp '{}' /usr/local/bin/ ';'
6465

6566
# Minimal ###############################################################
66-
FROM alpine:$base_image_version AS alpine-minimal
67+
FROM alpine:${base_image_version} AS minimal
6768
ARG pandoc_version=edge
6869
LABEL maintainer='Albert Krewinkel <albert+pandoc@tarleb.com>'
6970
LABEL org.pandoc.maintainer='Albert Krewinkel <albert+pandoc@tarleb.com>'
7071
LABEL org.pandoc.author="John MacFarlane"
71-
LABEL org.pandoc.version="$pandoc_version"
72+
LABEL org.pandoc.version="${pandoc_version}"
7273

7374
# Set user data directory
7475
ENV XDG_DATA_HOME=/usr/local/share
@@ -77,11 +78,13 @@ ENV XDG_DATA_HOME=/usr/local/share
7778
WORKDIR /data
7879
ENTRYPOINT ["/usr/local/bin/pandoc"]
7980

80-
COPY --from=alpine-builder \
81+
COPY --from=builder \
8182
/usr/local/bin/pandoc \
8283
/usr/local/bin/
8384

8485
# Add pandoc symlinks
86+
#
87+
# hadolint ignore=DL3018
8588
RUN ln -s /usr/local/bin/pandoc /usr/local/bin/pandoc-lua && \
8689
ln -s /usr/local/bin/pandoc /usr/local/bin/pandoc-server && \
8790
# Install runtime dependencies
@@ -90,16 +93,17 @@ RUN ln -s /usr/local/bin/pandoc /usr/local/bin/pandoc-lua && \
9093
libffi \
9194
lua5.4 && \
9295
# Create user data directory
93-
mkdir -p "$XDG_DATA_HOME"/pandoc
96+
mkdir -p "$$XDG_DATA_HOME"/pandoc
9497

9598
# Core ##################################################################
96-
FROM alpine-minimal AS alpine-core
97-
COPY --from=alpine-builder \
99+
FROM minimal AS core
100+
COPY --from=builder \
98101
/usr/local/bin/pandoc-crossref \
99102
/usr/local/bin/
100103

101104
# Additional packages frequently used during conversions
102105
# NOTE: `libsrvg`, pandoc uses `rsvg-convert` for working with svg images.
103106
# FIXME: Alpine 3.17 and later ships the binary in the rsvg-convert package.
107+
# hadolint ignore=DL3018
104108
RUN apk --no-cache add librsvg; \
105109
apk --no-cache add rsvg-convert || true

alpine/extra/Dockerfile

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

0 commit comments

Comments
 (0)