Files
PixivFE/Dockerfile.testing
T
2024-09-25 17:20:19 +10:00

75 lines
2.3 KiB
Docker

### Intended for testing PixivFE itself
### Not for production use
### Adapted from: https://github.com/playwright-community/playwright-go/blob/6b672dbd24505206feca7c2b660da8d616c6393f/Dockerfile.example
### Instructions:
# To build and run with Playwright:
# docker buildx build -t pixivfe-testing-playwright -f ./Dockerfile.testing --target with-playwright . --load
# docker run --rm -it --name pixivfe-testing-playwrightpixivfe-testing-playwright
# To build and run without Playwright:
# docker buildx build -t pixivfe-testing-no-playwright -f ./Dockerfile.testing --target without-playwright . --load
# docker run --rm -it --name pixivfe-testing-no-playwright pixivfe-testing-no-playwright
### Stage 1: Modules caching with correct Playwright CLI version
FROM golang:1.23.1-bookworm AS modules
COPY go.mod go.sum /modules/
WORKDIR /modules
RUN go mod download
RUN PWGO_VER=$(grep -oE "playwright-go v\S+" ./go.mod | sed 's/playwright-go //g') \
&& go install github.com/playwright-community/playwright-go/cmd/playwright@${PWGO_VER}
### Stage 2: Build application binary
FROM golang:1.23.1-bookworm AS builder
COPY --from=modules /go/pkg /go/pkg
COPY . /app
WORKDIR /app
RUN go build -o /app/pixivfe
### Stage 3a: Final with Playwright
FROM ubuntu:noble AS with-playwright
WORKDIR /app
# Copy the project directory
COPY . /app
# Copy playwright from modules stage
COPY --from=modules /go/bin/playwright /go/bin/playwright
# Copy built binary from builder stage
COPY --from=builder /app/pixivfe /app/pixivfe
# Install correct Go version
ADD https://golang.org/dl/go1.22.5.linux-amd64.tar.gz /usr/local/go
# Update PATH definition for Go binary and Playwright
ENV PATH="/usr/local/go/bin:/go/bin:${PATH}"
# Run playwright install --with-deps
RUN apt-get update && apt-get install -y ca-certificates tzdata \
# Install dependencies and all browsers (or specify one)
&& playwright install --with-deps \
&& rm -rf /var/lib/apt/lists/*
CMD ["/bin/bash"]
### Stage 3b: Final without Playwright
FROM ubuntu:noble AS without-playwright
WORKDIR /app
# Copy the project directory
COPY . /app
# Copy built binary from builder stage
COPY --from=builder /app/pixivfe /app/pixivfe
# Install correct Go version
ADD https://golang.org/dl/go1.22.5.linux-amd64.tar.gz /usr/local/go
# Update PATH definition for Go binary
ENV PATH="/usr/local/go/bin:${PATH}"
CMD ["/bin/bash"]