docker-tests: use userspace wireguard

pull/74/head
Jake McGinty 2021-05-20 03:16:28 +09:00
parent 5b744d1f78
commit 3fcacc2ad8
5 changed files with 75 additions and 30 deletions

View File

@ -1,41 +1,56 @@
#################################################################################################### ####################################################################################################
## Builder ## Builder
#################################################################################################### ####################################################################################################
FROM rust as planner FROM rust:slim as planner
RUN apt-get update && apt-get install -y build-essential musl-tools musl-dev clang libclang-dev libsqlite3-dev RUN apt-get update && apt-get install -y build-essential clang libclang-dev libsqlite3-dev
RUN update-ca-certificates
WORKDIR /app WORKDIR /app
RUN cargo install cargo-chef RUN cargo install cargo-chef
COPY . . COPY . .
RUN cargo chef prepare --recipe-path recipe.json RUN cargo chef prepare --recipe-path recipe.json
FROM rust as cacher FROM rust:slim as cacher
RUN apt-get update && apt-get install -y build-essential musl-tools musl-dev clang libclang-dev libsqlite3-dev RUN apt-get update && apt-get install -y build-essential clang libclang-dev libsqlite3-dev
RUN update-ca-certificates
WORKDIR /app WORKDIR /app
RUN cargo install cargo-chef RUN cargo install cargo-chef
COPY --from=planner /app/recipe.json recipe.json COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json RUN cargo chef cook --release --recipe-path recipe.json
FROM rust as builder FROM rust:slim as builder
RUN apt-get update && apt-get install -y build-essential musl-tools musl-dev clang libclang-dev libsqlite3-dev RUN apt-get update && apt-get install -y build-essential clang libclang-dev libsqlite3-dev
RUN update-ca-certificates
WORKDIR /app WORKDIR /app
COPY . . COPY . .
COPY --from=cacher /app/target target COPY --from=cacher /app/target target
RUN cargo build --release --bin innernet RUN cargo build --release --bin innernet
RUN strip /app/target/release/innernet RUN strip /app/target/release/innernet
FROM golang:latest as wireguard
ARG wg_go_tag=0.0.20210323
ARG wg_tools_tag=v1.0.20210315
RUN apt-get update && apt-get install -y git
RUN git clone -b $wg_go_tag --depth 1 https://git.zx2c4.com/wireguard-go && \
cd wireguard-go && \
make && \
make install
ENV WITH_WGQUICK=yes
RUN git clone -b $wg_tools_tag --depth 1 https://git.zx2c4.com/wireguard-tools && \
cd wireguard-tools && \
cd src && \
make && \
make install
#################################################################################################### ####################################################################################################
## Final image ## Final image
#################################################################################################### ####################################################################################################
FROM ubuntu:latest FROM debian:buster-slim
RUN apt-get update && apt-get install -y libsqlite3-dev iproute2 iputils-ping && rm -rf /var/lib/apt/lists/* RUN apt-get update && apt-get install -y libsqlite3-dev iproute2 iputils-ping && rm -rf /var/lib/apt/lists/*
WORKDIR /app WORKDIR /app
COPY ./docker-tests/start-client.sh ./ COPY ./docker-tests/start-client.sh ./
COPY --from=wireguard /usr/bin/wireguard-go /usr/bin/wg* /usr/bin/
COPY --from=builder /app/target/release/innernet /usr/bin/ COPY --from=builder /app/target/release/innernet /usr/bin/
CMD ["/app/start-client.sh"] CMD ["/app/start-client.sh"]

View File

@ -1,40 +1,55 @@
#################################################################################################### ####################################################################################################
## Builder ## Builder
#################################################################################################### ####################################################################################################
FROM rust as planner FROM rust:slim as planner
RUN apt-get update && apt-get install -y build-essential musl-tools musl-dev clang libclang-dev libsqlite3-dev RUN apt-get update && apt-get install -y build-essential clang libclang-dev libsqlite3-dev
RUN update-ca-certificates
WORKDIR /app WORKDIR /app
RUN cargo install cargo-chef RUN cargo install cargo-chef
COPY . . COPY . .
RUN cargo chef prepare --recipe-path recipe.json RUN cargo chef prepare --recipe-path recipe.json
FROM rust as cacher FROM rust:slim as cacher
RUN apt-get update && apt-get install -y build-essential musl-tools musl-dev clang libclang-dev libsqlite3-dev RUN apt-get update && apt-get install -y build-essential clang libclang-dev libsqlite3-dev
RUN update-ca-certificates
WORKDIR /app WORKDIR /app
RUN cargo install cargo-chef RUN cargo install cargo-chef
COPY --from=planner /app/recipe.json recipe.json COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json RUN cargo chef cook --release --recipe-path recipe.json
FROM rust as builder FROM rust:slim as builder
RUN apt-get update && apt-get install -y build-essential musl-tools musl-dev clang libclang-dev libsqlite3-dev RUN apt-get update && apt-get install -y build-essential clang libclang-dev libsqlite3-dev
RUN update-ca-certificates
WORKDIR /app WORKDIR /app
COPY . . COPY . .
COPY --from=cacher /app/target target COPY --from=cacher /app/target target
RUN cargo build --release --bin innernet-server RUN cargo build --release --bin innernet-server
RUN strip /app/target/release/innernet-server RUN strip /app/target/release/innernet-server
FROM golang:latest as wireguard
ARG wg_go_tag=0.0.20210323
ARG wg_tools_tag=v1.0.20210315
RUN apt-get update && apt-get install -y git
RUN git clone -b $wg_go_tag --depth 1 https://git.zx2c4.com/wireguard-go && \
cd wireguard-go && \
make && \
make install
ENV WITH_WGQUICK=yes
RUN git clone -b $wg_tools_tag --depth 1 https://git.zx2c4.com/wireguard-tools && \
cd wireguard-tools && \
cd src && \
make && \
make install
#################################################################################################### ####################################################################################################
## Final image ## Final image
#################################################################################################### ####################################################################################################
FROM ubuntu:latest FROM debian:buster-slim
RUN apt-get update && apt-get install -y libsqlite3-dev iproute2 iputils-ping && rm -rf /var/lib/apt/lists/* RUN apt-get update && apt-get install -y libsqlite3-dev iproute2 iputils-ping && rm -rf /var/lib/apt/lists/*
WORKDIR /app WORKDIR /app
COPY ./docker-tests/start-server.sh ./ COPY ./docker-tests/start-server.sh ./
COPY --from=wireguard /usr/bin/wireguard-go /usr/bin/wg* /usr/bin/
COPY --from=builder /app/target/release/innernet-server /usr/bin/ COPY --from=builder /app/target/release/innernet-server /usr/bin/
EXPOSE 51820/udp EXPOSE 51820/udp

View File

@ -32,11 +32,14 @@ info "Creating network."
NETWORK=$(cmd docker network create -d bridge --subnet=172.18.0.0/16 innernet) NETWORK=$(cmd docker network create -d bridge --subnet=172.18.0.0/16 innernet)
info "Starting server." info "Starting server."
SERVER_CONTAINER=$(cmd docker run -itd --rm \ SERVER_CONTAINER=$(cmd docker create -it --rm \
--network "$NETWORK" \ --network "$NETWORK" \
--ip 172.18.1.1 \ --ip 172.18.1.1 \
--volume /dev/net/tun:/dev/net/tun \
--env RUST_LOG=debug \
--cap-add NET_ADMIN \ --cap-add NET_ADMIN \
innernet-server) innernet-server)
cmd docker start -a "$SERVER_CONTAINER" &
info "server started as $SERVER_CONTAINER" info "server started as $SERVER_CONTAINER"
info "Waiting for server to initialize." info "Waiting for server to initialize."
@ -47,13 +50,14 @@ cmd docker cp "$SERVER_CONTAINER:/app/peer1.toml" "$tmp_dir"
PEER1_CONTAINER=$(cmd docker create --rm -it \ PEER1_CONTAINER=$(cmd docker create --rm -it \
--network "$NETWORK" \ --network "$NETWORK" \
--ip 172.18.1.2 \ --ip 172.18.1.2 \
--volume /dev/net/tun:/dev/net/tun \
--env INTERFACE=evilcorp \ --env INTERFACE=evilcorp \
--cap-add NET_ADMIN \ --cap-add NET_ADMIN \
innernet) innernet)
info "peer1 started as $PEER1_CONTAINER" info "peer1 started as $PEER1_CONTAINER"
cmd docker cp "$tmp_dir/peer1.toml" "$PEER1_CONTAINER:/app/invite.toml" cmd docker cp "$tmp_dir/peer1.toml" "$PEER1_CONTAINER:/app/invite.toml"
cmd docker start "$PEER1_CONTAINER" cmd docker start "$PEER1_CONTAINER"
sleep 5 sleep 10
info "Creating a new CIDR from first peer." info "Creating a new CIDR from first peer."
cmd docker exec "$PEER1_CONTAINER" innernet \ cmd docker exec "$PEER1_CONTAINER" innernet \
@ -85,6 +89,7 @@ info "Starting second peer."
PEER2_CONTAINER=$(docker create --rm -it \ PEER2_CONTAINER=$(docker create --rm -it \
--network "$NETWORK" \ --network "$NETWORK" \
--ip 172.18.1.3 \ --ip 172.18.1.3 \
--volume /dev/net/tun:/dev/net/tun \
--cap-add NET_ADMIN \ --cap-add NET_ADMIN \
--env INTERFACE=evilcorp \ --env INTERFACE=evilcorp \
innernet) innernet)

View File

@ -1,14 +1,16 @@
#!/bin/bash #!/bin/bash
set -e set -e
DEFAULT_ARGS="--backend userspace"
INTERFACE="${INTERFACE:-innernet}" INTERFACE="${INTERFACE:-innernet}"
innernet install \ innernet $DEFAULT_ARGS install \
--name "$INTERFACE" \ --name "$INTERFACE" \
--delete-invite \ --delete-invite \
--no-write-hosts \ --no-write-hosts \
/app/invite.toml /app/invite.toml
while true; do while true; do
innernet up --no-write-hosts "$INTERFACE" innernet $DEFAULT_ARGS up --no-write-hosts "$INTERFACE"
sleep 1 sleep 1
done done

View File

@ -1,19 +1,27 @@
#!/bin/bash #!/bin/bash
set -e set -e
innernet-server new \ DEFAULT_ARGS="--backend userspace"
innernet-server \
$DEFAULT_ARGS \
new \
--network-name "evilcorp" \ --network-name "evilcorp" \
--network-cidr "10.66.0.0/16" \ --network-cidr "10.66.0.0/16" \
--external-endpoint "172.18.1.1:51820" \ --external-endpoint "172.18.1.1:51820" \
--listen-port 51820 --listen-port 51820
innernet-server add-cidr evilcorp \ innernet-server \
$DEFAULT_ARGS \
add-cidr evilcorp \
--name "humans" \ --name "humans" \
--cidr "10.66.1.0/24" \ --cidr "10.66.1.0/24" \
--parent "evilcorp" \ --parent "evilcorp" \
--yes --yes
innernet-server add-peer evilcorp \ innernet-server \
$DEFAULT_ARGS \
add-peer evilcorp \
--name "admin" \ --name "admin" \
--cidr "humans" \ --cidr "humans" \
--admin true \ --admin true \
@ -22,4 +30,4 @@ innernet-server add-peer evilcorp \
--invite-expires "30d" \ --invite-expires "30d" \
--yes --yes
innernet-server serve evilcorp innernet-server $DEFAULT_ARGS serve evilcorp