68 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Docker
		
	
	
			
		
		
	
	
			68 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Docker
		
	
	
| # Global build argument
 | |
| ARG THTTPD_VER=2.29
 | |
| ARG DI_VER=1.2.5
 | |
| 
 | |
| FROM alpine:3 AS builder
 | |
| 
 | |
| 
 | |
| # =====BUILD BINARIES=====
 | |
| WORKDIR /usr/src
 | |
| ARG THTTPD_VER
 | |
| ARG DI_VER
 | |
| 
 | |
| # Install build dependencies
 | |
| # bash: required for dumb-init's Makefile
 | |
| # clang, build-base: compilation (I just like clang)
 | |
| # curl: downloading the tarballs
 | |
| # hugo: generating the static files
 | |
| RUN apk add --update --no-cache \
 | |
|     bash \
 | |
|     build-base \
 | |
|     clang \
 | |
|     curl \
 | |
|     hugo \
 | |
|     musl-dev
 | |
| 
 | |
| # Build thttpd
 | |
| RUN curl -sSL "https://www.acme.com/software/thttpd/thttpd-$THTTPD_VER.tar.gz" | \
 | |
|         tar xzf - && \
 | |
|     cd "thttpd-$THTTPD_VER" && \
 | |
|     CC=clang ./configure && \
 | |
|     make CCOPT="-O3 -s -static" -j$(nproc)
 | |
| 
 | |
| # Build dumb-init
 | |
| # dumb-init's Makefile already specifies static build flags, so we don't have to specify them
 | |
| RUN curl -sSL "https://github.com/Yelp/dumb-init/archive/refs/tags/v$DI_VER.tar.gz" | \
 | |
|     tar xzf - && \
 | |
|     cd "dumb-init-$DI_VER" && \
 | |
|     CC=clang make build
 | |
| 
 | |
| 
 | |
| # =====BUILD BLOG=====
 | |
| WORKDIR /usr/src/app
 | |
| 
 | |
| # Copy site files for building
 | |
| COPY . ./
 | |
| 
 | |
| # Generate the site
 | |
| # The find command fixes file permissions, because thttpd thinks executables should be CGI files
 | |
| RUN hugo --minify && \
 | |
|     find public -type f -exec chmod 644 {} \;
 | |
| 
 | |
| 
 | |
| # ====CREATE RELEASE IMAGE====
 | |
| FROM scratch
 | |
| ARG THTTPD_VER
 | |
| ARG DI_VER
 | |
| 
 | |
| # Copy over binary & static files
 | |
| COPY --from=builder /usr/src/thttpd-$THTTPD_VER/thttpd /bin/thttpd
 | |
| COPY --from=builder /usr/src/dumb-init-$DI_VER/dumb-init /bin/dumb-init
 | |
| COPY --from=builder /usr/src/app/public /static
 | |
| 
 | |
| # A static file server doesn't need root
 | |
| USER 82:82
 | |
| 
 | |
| ENTRYPOINT [ "/bin/dumb-init", "--" ]
 | |
| CMD [ "/bin/thttpd", "-D", "-d", "/static", "-p", "8080" ]
 |