From 211477b340ac467bb4ccfe0d42cef9c8ce033f19 Mon Sep 17 00:00:00 2001 From: DanGould Date: Tue, 26 Nov 2024 15:55:48 -0500 Subject: [PATCH] Build payjoin-directory with Docker Include a docker-compose.yml template to run - payjoin-directory - redis - nginx - certbot in a valid configuration. Close #143 --- payjoin-directory/Dockerfile | 37 +++++++++++++++++++ payjoin-directory/docker-compose.yml | 55 ++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 payjoin-directory/Dockerfile create mode 100644 payjoin-directory/docker-compose.yml diff --git a/payjoin-directory/Dockerfile b/payjoin-directory/Dockerfile new file mode 100644 index 00000000..c296bf72 --- /dev/null +++ b/payjoin-directory/Dockerfile @@ -0,0 +1,37 @@ +# Use the official Rust image as the builder +FROM --platform=linux/amd64 rust:1.75-slim as builder + +WORKDIR /usr/src/payjoin-directory + +# Install cross-compilation dependencies +RUN apt-get update && \ + apt-get install -y \ + build-essential \ + musl-tools \ + musl-dev \ + pkg-config \ + gcc-multilib \ + && rm -rf /var/lib/apt/lists/* + +# Set the linker +ENV CC_x86_64_unknown_linux_musl=musl-gcc +ENV AR_x86_64_unknown_linux_musl=ar + +# Add the x86_64-unknown-linux-musl target +RUN rustup target add x86_64-unknown-linux-musl + +# Copy the manifest and source code +COPY payjoin-directory/Cargo.toml ./ +COPY payjoin-directory/src/ ./src/ + +# Build the binary +RUN cargo build --release --target x86_64-unknown-linux-musl + +# Create final minimal image +FROM --platform=linux/amd64 alpine:latest + +# Copy the binary from builder +COPY --from=builder /usr/src/payjoin-directory/target/x86_64-unknown-linux-musl/release/payjoin-directory ./ + +# Run the binary +ENTRYPOINT ["./payjoin-directory"] \ No newline at end of file diff --git a/payjoin-directory/docker-compose.yml b/payjoin-directory/docker-compose.yml new file mode 100644 index 00000000..07a13321 --- /dev/null +++ b/payjoin-directory/docker-compose.yml @@ -0,0 +1,55 @@ +version: '3.8' + +services: + nginx: + image: nginx:latest + ports: + - "80:80" + - "443:443" + volumes: + - ./nginx/logs:/var/log/nginx + - ./nginx/conf.d:/etc/nginx/conf.d + - ./nginx/certs:/etc/ssl/certs + - ./nginx/html:/var/www/html + networks: + - payjoin-network + + certbot: + image: certbot/certbot + volumes: + - ./nginx/certs:/etc/letsencrypt + - ./nginx/html:/var/www/html + entrypoint: /bin/sh -c 'trap exit TERM; while :; do certbot renew --webroot -w /var/www/html --deploy-hook "nginx -s reload"; sleep 12h & wait $${!}; done;' + depends_on: + - nginx + networks: + - payjoin-network + + payjoin-directory: + image: dangould/payjoin-directory:0.0.1-rc0 + environment: + RUST_LOG: "trace" + PJ_DB_HOST: "redis:6379" + PJ_DIR_PORT: "8080" + ports: + - "8080:8080" + depends_on: + - redis + networks: + - payjoin-network + + redis: + image: redis:latest + ports: + - "6379:6379" + volumes: + - redis-data:/data + networks: + - payjoin-network + +networks: + payjoin-network: + driver: bridge + +volumes: + redis-data: