added frontend build multistage docker build

This commit is contained in:
euzu
2024-03-28 11:58:00 +01:00
parent cb8604a14c
commit bdce4ff5e0
4 changed files with 61 additions and 9 deletions
+2
View File
@@ -1,3 +1,5 @@
target/
bin/
docker/
frontend/node_modules/
frontend/build/
+20 -2
View File
@@ -5,7 +5,7 @@ RUN apt-get update && \
apt-get install pkg-config musl-tools libssl-dev
RUN rustup update
ENV RUSTFLAGS='-C target-feature=+crt-static'
ENV RUSTFLAGS='--remap-path-prefix $HOME=~ -C target-feature=+crt-static'
COPY . /src
WORKDIR /src
@@ -13,6 +13,22 @@ WORKDIR /src
RUN rustup target add x86_64-unknown-linux-musl
RUN cargo build --target x86_64-unknown-linux-musl --release
FROM node:lts as node-build
ENV NODE_OPTIONS=--openssl-legacy-provider
COPY ./frontend /app
WORKDIR /app
RUN yarn install \
--prefer-offline \
--frozen-lockfile \
--non-interactive \
--production=false
RUN yarn build
RUN rm -rf node_modules
# Final container
FROM scratch
@@ -22,7 +38,9 @@ COPY --from=rust-build /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=rust-build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=rust-build /src/target/x86_64-unknown-linux-musl/release/m3u-filter /m3u-filter
COPY ./config /config
COPY --from=node-build /app/build /web
# config should be mounted as volume
# COPY ./config /config
ENTRYPOINT ["/m3u-filter"]
CMD ["-s", "-p", "/config"]
+13
View File
@@ -0,0 +1,13 @@
FROM gcr.io/distroless/base-debian12 as build
FROM scratch
WORKDIR /
COPY --from=build /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY ./m3u-filter /
COPY ./web /web
CMD ["./m3u-filter", "-s", "-p", "/config"]
+26 -7
View File
@@ -1,10 +1,29 @@
# Dockerize
To dockerize m3u-filter, you need to compile a static build.
The static build can creted with `bin\build_lin_static.sh`.
Description of static binary compiling is in the main `README.md`
# Build docker image
Change into the root directory and run:
To create a docker image type:
`docker build -t m3u-filter .`
You have to copy all the needed files (look at the Dockerfile) into the current directory.
```shell
docker build --rm -f docker/Dockerfile -t m3u-filter .
```
This will build the complete project and create a docker image.
To start the container, you can use the `docker-compose.yml`
But you need to change `image: ghcr.io/euzu/m3u-filter:latest` to `image: m3u-filter`
# Manual docker image
You want to build the binary and web folder manually and create a docker image.
To dockerize m3u-filter, you need to compile a static build.
The static build can created with `bin\build_lin_static.sh`.
Description of static binary compiling is in the main `README.md`
Then you need to compile the frontend with `yarn build`
Change into the `docker` directory and copy all the needed files (look at the Dockerfile) into the current directory.
To create a docker image type:
`docker -f Dockerfile-manual build -t m3u-filter .`
To start the container, you can use the `docker-compose.yml`
But you need to change `image: ghcr.io/euzu/m3u-filter:latest` to `image: m3u-filter`