|
| 1 | +name: Build MikTeX images |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + workflow_dispatch: |
| 6 | + |
| 7 | +jobs: |
| 8 | + MikTeX: |
| 9 | + name: Build MikTeX base-image |
| 10 | + runs-on: ubuntu-24.04 |
| 11 | + |
| 12 | + outputs: |
| 13 | + base_image_os_version: ${{ steps.variables.outputs.base_image_os_version }} |
| 14 | + base_image_py_version: ${{ steps.variables.outputs.base_image_py_version }} |
| 15 | + miktex_image_ns: ${{ steps.variables.outputs.miktex_image_ns }} |
| 16 | + miktex_image_name: ${{ steps.variables.outputs.miktex_image_name }} |
| 17 | + miktex_image_tag: ${{ steps.variables.outputs.miktex_image_tag }} |
| 18 | + miktex_image: ${{ steps.variables.outputs.miktex_image }} |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: 🖉 Variables |
| 22 | + id: variables |
| 23 | + run: | |
| 24 | + base_image_name="python" |
| 25 | + base_image_py_version="3.13" |
| 26 | + base_image_os_version="bookworm" |
| 27 | +
|
| 28 | + image_name="miktex" |
| 29 | + image_tag="latest" |
| 30 | +
|
| 31 | + tee "${GITHUB_OUTPUT}" <<EOF |
| 32 | + base_image_name=${base_image_name} |
| 33 | + base_image_py_version=${base_image_py_version} |
| 34 | + base_image_os_version=${base_image_os_version} |
| 35 | + base_image=${base_image_name}:${base_image_py_version}-slim-${base_image_os_version} |
| 36 | + |
| 37 | + miktex_image_ns=${{ vars.DOCKERHUB_NAMESPACE }} |
| 38 | + miktex_image_name=${image_name} |
| 39 | + miktex_image_tag=${image_tag} |
| 40 | + miktex_image=${{ vars.DOCKERHUB_NAMESPACE }}/${image_name}:${image_tag} |
| 41 | + EOF |
| 42 | +
|
| 43 | + - name: ⏬ Checkout repository |
| 44 | + uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: 🐋 Building MikTeX image |
| 47 | + id: build |
| 48 | + run: | |
| 49 | + ANSI_RED=$'\x1b[31m' |
| 50 | + ANSI_GREEN=$'\x1b[32m' |
| 51 | + ANSI_YELLOW=$'\x1b[33m' |
| 52 | + ANSI_BLUE=$'\x1b[34m' |
| 53 | + ANSI_CYAN=$'\x1b[36m' |
| 54 | + ANSI_DARK_GRAY=$'\x1b[90m' |
| 55 | + ANSI_NOCOLOR=$'\x1b[0m' |
| 56 | + |
| 57 | + RemoveComments() { |
| 58 | + local OutputFile="${2:-$1}" |
| 59 | + |
| 60 | + printf "%s\n" "Removing comments from '$1' and writing to '${OutputFile}'." |
| 61 | + grep -v '^\s*$\|^\s*\#' "$1" > "${OutputFile}" |
| 62 | + |
| 63 | + printf "%s\n" "${ANSI_BLUE}${OutputFile}${ANSI_NOCOLOR}" |
| 64 | + printf "%s\n" "${ANSI_BLUE}--------------------------------------------------------------------------------${ANSI_NOCOLOR}" |
| 65 | + while IFS='' read -r line; do |
| 66 | + printf "%s\n" " ${ANSI_CYAN}$line${ANSI_NOCOLOR}" |
| 67 | + done < "${OutputFile}" |
| 68 | + printf "%s\n" "${ANSI_BLUE}--------------------------------------------------------------------------------${ANSI_NOCOLOR}" |
| 69 | + } |
| 70 | +
|
| 71 | + DockerImageSizeUncompressed() { |
| 72 | + docker image inspect $1 --format='{{.Size}}' | numfmt --to=iec --format '%.2f' |
| 73 | + } |
| 74 | +
|
| 75 | + printf "%s\n" "Convert 'Common.list' to 'Packages.list' ..." |
| 76 | + RemoveComments Common.list Packages.list |
| 77 | +
|
| 78 | + printf "%s\n" "Building docker file 'Dockerfile' ..." |
| 79 | + docker buildx build \ |
| 80 | + --file Dockerfile \ |
| 81 | + --build-arg IMAGE=${{ steps.variables.outputs.base_image }} \ |
| 82 | + --build-arg OS_VERSION=${{ steps.variables.outputs.base_image_os_version }} \ |
| 83 | + --build-arg PY_VERSION=${{ steps.variables.outputs.base_image_py_version }} \ |
| 84 | + --tag "${{ steps.variables.outputs.miktex_image }}" \ |
| 85 | + . 2>&1 \ |
| 86 | + | ./Docker.buildx.sh |
| 87 | +
|
| 88 | + printf "%s\n" "Docker image '${{ steps.variables.outputs.miktex_image }}' has $(DockerImageSizeUncompressed ${{ steps.variables.outputs.miktex_image }})" |
| 89 | +
|
| 90 | + - name: ☑ Checking MikTeX image '${{ steps.variables.outputs.miktex_image }}' |
| 91 | + run: | |
| 92 | + printf "%s\n" "Docker image '${{ steps.variables.outputs.miktex_image }}' has $(DockerImageSizeUncompressed ${{ steps.variables.outputs.miktex_image }})" |
| 93 | + |
| 94 | + docker container run --rm ${{ steps.variables.outputs.miktex_image }} 'printf "%s\n" "which pdflatex: $(which pdflatex)"' |
| 95 | +
|
| 96 | + - name: 🔑 Login and push '${{ steps.variables.outputs.miktex_image }}' to Docker Hub |
| 97 | + run: | |
| 98 | + printf "%s\n" "Login at Docker Hub ..." |
| 99 | + printf "%s\n" "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ vars.DOCKERHUB_USERNAME }} --password-stdin |
| 100 | + |
| 101 | + printf "%s\n" "Docker image '${{ steps.variables.outputs.miktex_image }}' has $(DockerImageSizeUncompressed ${{ steps.variables.outputs.miktex_image }})" |
| 102 | + docker image push ${{ steps.variables.outputs.miktex_image }} |
| 103 | +
|
| 104 | + Specific: |
| 105 | + name: ${{ matrix.icon }} Build specific MikTeX image for ${{ matrix.name }} |
| 106 | + runs-on: ubuntu-24.04 |
| 107 | + needs: |
| 108 | + - MikTeX |
| 109 | + strategy: |
| 110 | + fail-fast: false |
| 111 | + matrix: |
| 112 | + include: |
| 113 | + - {'icon': '📓', 'name': 'Sphinx', 'image': 'sphinx'} |
| 114 | + |
| 115 | + steps: |
| 116 | + - name: 🖉 Variables |
| 117 | + id: variables |
| 118 | + run: | |
| 119 | + tee "${GITHUB_OUTPUT}" <<EOF |
| 120 | + specific_image_ns=base_image_ns="${{ needs.MikTeX.outputs.miktex_image_ns }}" |
| 121 | + specific_image_name="${{ needs.MikTeX.outputs.miktex_image_name }}" |
| 122 | + specific_image_tag="${{ matrix.name }}" |
| 123 | + specific_image=${{ needs.MikTeX.outputs.miktex_image_ns }}/${{ needs.MikTeX.outputs.miktex_image_name }}:${{ matrix.image }} |
| 124 | + EOF |
| 125 | +
|
| 126 | + - name: ⏬ Checkout repository |
| 127 | + uses: actions/checkout@v4 |
| 128 | + |
| 129 | + - name: 🐋 Building MikTeX image for ${{ matrix.name }} |
| 130 | + id: build |
| 131 | + run: | |
| 132 | + ANSI_RED=$'\x1b[31m' |
| 133 | + ANSI_GREEN=$'\x1b[32m' |
| 134 | + ANSI_YELLOW=$'\x1b[33m' |
| 135 | + ANSI_BLUE=$'\x1b[34m' |
| 136 | + ANSI_CYAN=$'\x1b[36m' |
| 137 | + ANSI_DARK_GRAY=$'\x1b[90m' |
| 138 | + ANSI_NOCOLOR=$'\x1b[0m' |
| 139 | + |
| 140 | + RemoveComments() { |
| 141 | + local OutputFile="${2:-$1}" |
| 142 | + |
| 143 | + printf "%s\n" "Removing comments from '$1' and writing to '${OutputFile}'." |
| 144 | + grep -v '^\s*$\|^\s*\#' "$1" > "${OutputFile}" |
| 145 | + |
| 146 | + printf "%s\n" "${ANSI_BLUE}${OutputFile}${ANSI_NOCOLOR}" |
| 147 | + printf "%s\n" "${ANSI_BLUE}--------------------------------------------------------------------------------${ANSI_NOCOLOR}" |
| 148 | + while IFS='' read -r line; do |
| 149 | + printf "%s\n" " ${ANSI_CYAN}$line${ANSI_NOCOLOR}" |
| 150 | + done < "${OutputFile}" |
| 151 | + printf "%s\n" "${ANSI_BLUE}--------------------------------------------------------------------------------${ANSI_NOCOLOR}" |
| 152 | + } |
| 153 | +
|
| 154 | + DockerImageSizeUncompressed() { |
| 155 | + docker image inspect $1 --format='{{.Size}}' | numfmt --to=iec --format '%.2f' |
| 156 | + } |
| 157 | +
|
| 158 | + printf "%s\n" "Convert '${{ matrix.name }}.list' to 'Packages.list' ..." |
| 159 | + RemoveComments ${{ matrix.name }}.list Packages.list |
| 160 | +
|
| 161 | + printf "%s\n" "Building docker file 'Dockerfile' ..." |
| 162 | + docker buildx build \ |
| 163 | + --file Dockerfile.Specific \ |
| 164 | + --build-arg "IMAGE=${{ needs.MikTeX.outputs.miktex_image }}" \ |
| 165 | + --build-arg "BASE_VARIANT=Debian ${{ needs.MikTeX.outputs.base_image_os_version }} with Python ${{ needs.MikTeX.outputs.base_image_py_version }}" \ |
| 166 | + --build-arg "VARIANT=${{ matrix.name }}" \ |
| 167 | + --tag "${{ steps.variables.outputs.specific_image }}" \ |
| 168 | + . 2>&1 \ |
| 169 | + | ./Docker.buildx.sh |
| 170 | +
|
| 171 | + printf "%s\n" "Docker image '${{ steps.variables.outputs.specific_image }}' has $(DockerImageSizeUncompressed ${{ steps.variables.outputs.specific_image }})" |
| 172 | +
|
| 173 | + - name: ☑ Checking MikTeX image '${{ steps.variables.outputs.specific_image }}' |
| 174 | + run: | |
| 175 | + printf "%s\n" "Docker image '${{ steps.variables.outputs.specific_image }}' has $(DockerImageSizeUncompressed ${{ steps.variables.outputs.specific_image }})" |
| 176 | + |
| 177 | + docker container run --rm ${{ steps.variables.outputs.specific_image }} 'printf "%s\n" "which pdflatex: $(which pdflatex)"' |
| 178 | +
|
| 179 | + - name: 🔑 Login and push '${{ steps.variables.outputs.specific_image }}' to Docker Hub |
| 180 | + run: | |
| 181 | + printf "%s\n" "Login at Docker Hub ..." |
| 182 | + printf "%s\n" "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ vars.DOCKERHUB_USERNAME }} --password-stdin |
| 183 | + |
| 184 | + printf "%s\n" "Docker image '${{ steps.variables.outputs.specific_image }}' has $(DockerImageSizeUncompressed ${{ steps.variables.outputs.specific_image }})" |
| 185 | + docker image push ${{ steps.variables.outputs.specific_image }} |
0 commit comments