dev-ops/faster-docker-build-times

This commit is contained in:
Thilo Behnke
2022-06-16 16:56:16 +02:00
parent 9106f6c2a3
commit 89db741ae7
11 changed files with 34 additions and 19 deletions

View File

View File

@@ -1,6 +1,6 @@
pkg
tests
dist
node_modules
**/node_modules
Dockerfile
.dockerignore

View File

@@ -6,8 +6,8 @@ RUN apt-get install curl
RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
RUN mkdir -p /build/client/wasm
ADD ./pong /build/pong
ADD ./client/wasm /build/client/wasm
ADD ./wasm /build/client/wasm
ADD ./wasm/pong /build/pong
WORKDIR /build/client/wasm
RUN wasm-pack build
@@ -15,7 +15,7 @@ FROM node:12 as www_build_stage
RUN mkdir /build
ADD ./client/www /build/www
ADD ./www /build/www
RUN ls /build/www
RUN mkdir /build/www/node_modules
WORKDIR /build/www
@@ -29,5 +29,5 @@ FROM nginx:latest
COPY --from=www_build_stage /build/www/dist/ /usr/share/nginx/pong/web
COPY ./client/nginx/default.conf /etc/nginx/conf.d/default.conf
COPY ./client/nginx/nginx.conf /etc/nginx/nginx.conf
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
COPY ./nginx/nginx.conf /etc/nginx/nginx.conf

1
client/wasm/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
pong

View File

@@ -33,8 +33,7 @@ services:
server:
container_name: pong_server
build:
context: ./
dockerfile: ./server/Dockerfile
context: ./server
ports:
- '4000:4000'
restart: on-failure
@@ -46,8 +45,7 @@ services:
nginx:
container_name: pong_nginx
build:
context: ./
dockerfile: ./client/Dockerfile
context: ./client
ports:
- '80:80'
network_mode: 'host'

View File

@@ -2,6 +2,8 @@
set -e
source .env
docker exec pong_server_kafka /opt/bitnami/kafka/bin/kafka-topics.sh --create --topic session --bootstrap-server "$KAFKA_HOST:$KAFKA_PORT"
docker exec pong_server_kafka /opt/bitnami/kafka/bin/kafka-topics.sh --create --topic move --bootstrap-server "$KAFKA_HOST:$KAFKA_PORT"
docker exec pong_server_kafka /opt/bitnami/kafka/bin/kafka-topics.sh --create --topic status --bootstrap-server "$KAFKA_HOST:$KAFKA_PORT"

View File

@@ -2,11 +2,15 @@
set -e
cd server || exit
echo "Environment prepared."
source .env
echo "Copy local dependencies into components."
cp -r ./pong ./client/wasm/
cp -r ./pong ./server/
echo "Start docker containers."
docker-compose down
docker-compose up -d --build --force-recreate kafka zookeeper nginx
echo "Initialize kafka."
./init-kafka.sh

View File

@@ -2,13 +2,19 @@
set -e
cd server || exit
echo "Environment prepared."
source .env
echo "Copy local dependencies into components."
cp -r ./pong ./client/wasm/
cp -r ./pong ./server/
echo "Start docker containers."
docker-compose down
docker-compose up -d --build --force-recreate
docker exec pong_server_kafka /opt/bitnami/kafka/bin/kafka-topics.sh --create --topic session --bootstrap-server "$KAFKA_HOST:$KAFKA_PORT"
docker exec pong_server_kafka /opt/bitnami/kafka/bin/kafka-topics.sh --create --topic move --bootstrap-server "$KAFKA_HOST:$KAFKA_PORT"
docker exec pong_server_kafka /opt/bitnami/kafka/bin/kafka-topics.sh --create --topic status --bootstrap-server "$KAFKA_HOST:$KAFKA_PORT"
docker exec pong_server_kafka /opt/bitnami/kafka/bin/kafka-topics.sh --create --topic input --bootstrap-server "$KAFKA_HOST:$KAFKA_PORT"
echo "Remove temporary local dependencies from components."
rm -rf ./client/wasm/pong
rm -rf ./server/pong
echo "Initialize kafka."
./init-kafka.sh

1
server/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
pong

View File

@@ -1,8 +1,8 @@
FROM rust:latest as build_stage
RUN mkdir /build
ADD ./ /build/server
ADD ./pong /build/pong
ADD ./server /build/server
WORKDIR /build/server
RUN cargo build --release

View File

@@ -252,6 +252,9 @@ async fn serve_websocket(
break;
}
}
// Avoid starvation of read thread (?)
// TODO: How to avoid this? This is very bad for performance.
sleep(Duration::from_millis(1)).await;
}
});
Ok(())