mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 18:18:55 +00:00
Considered using Elixir and Rust to write the tests. For Elixir, `wallaby` doesn't seem to have a way to attach to an existing `chromium` instance, launching it each time, which makes it hard to coordinate with the relay restart. For Rust we considered `thirtyfour` which would be very nice since we could test both firefox and chrome but each time it connects to the instance it launches a new session making it hard to test the DNS cache behavior. We also considered `chrome_headless` for Rust it needs a small patch to prevent it from closing the browser after `Drop` but it still presents a problem, since it has no easy way to retrieve if loading a page has succeeded. There are some workarounds such as retrieving the title that we could have used but after some testing they are quite finnicky and we don't want that for CI. So I ended up settling for TypeScript but I'm open to other options, or a fix for the previous ones! There are some modifications still incoming for this PR, around the test name and that sleep in the middle of the test doesn't look good so I will probably add some retries, but the gist is here, will keep it in draft until we expect it to be passing. So feel free to do some initial reviews. Note: the number of lines changed is greatly exaggerated by `package.lock` --------- Signed-off-by: Thomas Eizinger <thomas@eizinger.io> Co-authored-by: Jamil Bou Kheir <jamilbk@users.noreply.github.com> Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
105 lines
2.6 KiB
Docker
105 lines
2.6 KiB
Docker
ARG ALPINE_VERSION=3.19
|
|
ARG CARGO_CHEF_VERSION="0.1.62"
|
|
|
|
# This image is used to prepare Cargo Chef which is used to cache dependencies
|
|
FROM rust:1.77-alpine${ALPINE_VERSION} as chef
|
|
|
|
ARG CARGO_CHEF_VERSION
|
|
RUN set -xe \
|
|
&& apk add --no-cache musl-dev \
|
|
&& cargo install cargo-chef --locked --version=${CARGO_CHEF_VERSION} \
|
|
&& rm -rf $CARGO_HOME/registry/
|
|
|
|
## See https://github.com/LukeMathWalker/cargo-chef/issues/231.
|
|
COPY rust-toolchain.toml rust-toolchain.toml
|
|
|
|
RUN set -xe \
|
|
&& rustup show
|
|
|
|
WORKDIR /build
|
|
|
|
# Create a cache recipe for dependencies, which allows
|
|
# to leverage Docker layer caching in a later build stage
|
|
FROM chef as planner
|
|
|
|
COPY . .
|
|
|
|
RUN cargo chef prepare --recipe-path recipe.json
|
|
|
|
# Build dependencies and application application
|
|
FROM chef as builder
|
|
|
|
COPY --from=planner /build/recipe.json .
|
|
|
|
ARG PACKAGE
|
|
RUN set -xe \
|
|
&& cargo chef cook --recipe-path recipe.json --bin ${PACKAGE}
|
|
|
|
COPY . .
|
|
|
|
ARG TARGET
|
|
ARG PACKAGE
|
|
RUN cargo build -p ${PACKAGE} $([ -n "${TARGET}" ] && "--target ${TARGET}")
|
|
|
|
# Image which is used to run the application binary
|
|
FROM alpine:${ALPINE_VERSION} AS runtime
|
|
|
|
# Important! Update this no-op ENV variable when this Dockerfile
|
|
# is updated with the current date. It will force refresh of all
|
|
# of the base images and things like `apk add` won't be using
|
|
# old cached versions when the Dockerfile is built.
|
|
ENV REFRESHED_AT=2023-10-23 \
|
|
LANG=C.UTF-8 \
|
|
TERM=xterm \
|
|
RUST_BACKTRACE=1 \
|
|
RUST_LOG=str0m=warn,info
|
|
|
|
WORKDIR /bin
|
|
|
|
## curl is needed by the entrypoint script
|
|
RUN set -xe \
|
|
&& apk add --no-cache curl
|
|
|
|
COPY ./docker-init.sh .
|
|
|
|
## iptables are needed only by gateway for masquerading
|
|
ARG PACKAGE
|
|
RUN set -xe \
|
|
&& \[ "${PACKAGE}" = "firezone-gateway" ] && apk add --no-cache iptables ip6tables || true
|
|
|
|
ENTRYPOINT ["docker-init.sh"]
|
|
|
|
ENV PACKAGE=${PACKAGE}
|
|
|
|
CMD $PACKAGE
|
|
|
|
# used as a base for dev and test
|
|
FROM runtime as test
|
|
|
|
RUN set -xe \
|
|
&& apk add --no-cache iperf3 bind-tools iproute2 jq procps
|
|
|
|
# used for local development
|
|
FROM test AS dev
|
|
ARG TARGET
|
|
COPY --from=builder /build/target/${TARGET}/debug/${PACKAGE} .
|
|
|
|
# Build an image for GitHub Actions which includes debug asserts and more test utilities
|
|
FROM test AS debug
|
|
|
|
ARG TARGET
|
|
## Build first with `cross build --target ${TARGET} -p ${PACKAGE} && mv /target/${TARGET}/release/${PACKAGE} .`
|
|
COPY ${PACKAGE} .
|
|
|
|
RUN set -xe \
|
|
&& apk add --no-cache nodejs npm chromium
|
|
COPY --from=browser-tests . .
|
|
RUN npm install
|
|
|
|
# Build a production image from including a binary compiled on the host
|
|
FROM runtime AS release
|
|
|
|
ARG TARGET
|
|
## Build first with `cross build --target ${TARGET} -p ${PACKAGE} --release && mv /target/${TARGET}/release/${PACKAGE} .`
|
|
COPY ${PACKAGE} .
|