-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Docker for Server-Based gRPC and REST gateway
- Loading branch information
Showing
23 changed files
with
311 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Include any files or directories that you don't want to be copied to your | ||
# container here (e.g., local build artifacts, temporary files, etc.). | ||
# | ||
# For more help, visit the .dockerignore file reference guide at | ||
# https://docs.docker.com/go/build-context-dockerignore/ | ||
|
||
**/.DS_Store | ||
**/.classpath | ||
**/.dockerignore | ||
**/.env | ||
**/.git | ||
.idea/.gitignore | ||
**/.project | ||
**/.settings | ||
**/.toolstarget | ||
**/.vs | ||
**/.vscode | ||
**/*.*proj.user | ||
**/.idea | ||
**/*.iml | ||
**/*.dbmdl | ||
**/*.jfm | ||
**/charts | ||
**/docker-compose* | ||
**/compose.y*ml | ||
**/Dockerfile* | ||
**/node_modules | ||
**/npm-debug.log | ||
**/secrets.dev.yaml | ||
**/values.dev.yaml | ||
/bin | ||
/target | ||
LICENSE | ||
README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ target/ | |
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb | ||
|
||
**/.env | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
ARG RUST_VERSION=1.81.0 | ||
ARG APP_NAME=drive-deposits-grpc-server | ||
|
||
################################################################################ | ||
# Create a stage for building the application. | ||
|
||
FROM rust:${RUST_VERSION}-alpine AS build | ||
ARG APP_NAME | ||
# not used as we are using a bind mount with absolute path | ||
WORKDIR /drive-deposits | ||
|
||
# Install host build dependencies. | ||
RUN apk add --no-cache clang lld musl-dev git | ||
|
||
RUN apk add --no-cache protobuf-dev | ||
|
||
|
||
# Build the application. | ||
# Mounting for caching dependencies and build artifacts | ||
RUN --mount=type=cache,target=/usr/local/cargo/registry \ | ||
--mount=type=cache,target=/usr/local/cargo/git/db \ | ||
--mount=type=cache,target=/tmp/cargo-target \ | ||
--mount=type=bind,source=.,target=/tmp/build \ | ||
set -x && \ | ||
ls -la /drive-deposits && \ | ||
cd /tmp/build && \ | ||
mkdir -p /tmp/cargo-target && \ | ||
CARGO_TARGET_DIR=/tmp/cargo-target cargo build --package $APP_NAME --locked --release && \ | ||
echo "Contents of /tmp/cargo-target/release/ directory:" && \ | ||
ls -la /tmp/cargo-target/release/ && \ | ||
if [ -f /tmp/cargo-target/release/$APP_NAME ]; then \ | ||
mkdir -p /bin/server && \ | ||
cp /tmp/cargo-target/release/$APP_NAME /bin/server/$APP_NAME && \ | ||
echo "Contents of /bin/server directory:" && \ | ||
ls -la /bin/server; \ | ||
else \ | ||
echo "Binary $APP_NAME not found in /tmp/cargo-target/release/"; \ | ||
exit 1; \ | ||
fi | ||
|
||
################################################################################# | ||
# Create a new stage for running the application | ||
# could use distroless | ||
# FROM gcr.io/distroless/cc-debian11 | ||
# or slim | ||
# FROM debian:buster-slim | ||
# this is docker init by default | ||
FROM alpine:3.18 AS final | ||
|
||
WORKDIR /bin | ||
|
||
# Create a non-privileged user that the app will run under. | ||
# See https://docs.docker.com/go/dockerfile-user-best-practices/ | ||
ARG UID=10001 | ||
RUN adduser \ | ||
--disabled-password \ | ||
--gecos "" \ | ||
--home "/nonexistent" \ | ||
--shell "/sbin/nologin" \ | ||
--no-create-home \ | ||
--uid "${UID}" \ | ||
appuser | ||
USER appuser | ||
|
||
WORKDIR /bin | ||
|
||
COPY --from=build /bin/server/$APP_NAME . | ||
|
||
RUN echo "Contents of workdir /bin directory for drive-deposits-grpc-server in final:" && \ | ||
ls -la /bin | ||
|
||
|
||
EXPOSE 50052 | ||
|
||
ENV RUST_LOG="drive_deposits_rest_types=debug,drive_deposits_proto_grpc_types=debug,drive_deposits_event_source=debug,drive_deposits_cal_types=debug,drive_deposits_grpc_server=debug" | ||
|
||
ENV SEND_CAL_EVENTS="true" | ||
ENV USE_LOCALSTACK="false" | ||
|
||
|
||
CMD ["/bin/drive-deposits-grpc-server"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
ARG RUST_VERSION=1.81.0 | ||
ARG APP_NAME=drive-deposits-rest-gateway-server | ||
|
||
################################################################################ | ||
# Create a stage for building the application. | ||
|
||
FROM rust:${RUST_VERSION}-alpine AS build | ||
ARG APP_NAME | ||
# not used as we are using a bind mount with absolute path | ||
WORKDIR /drive-deposits | ||
|
||
# Install host build dependencies. | ||
RUN apk add --no-cache clang lld musl-dev git | ||
|
||
RUN apk add --no-cache protobuf-dev | ||
|
||
|
||
# Build the application. | ||
# Mounting for caching dependencies and build artifacts | ||
RUN --mount=type=cache,target=/usr/local/cargo/registry \ | ||
--mount=type=cache,target=/usr/local/cargo/git/db \ | ||
--mount=type=cache,target=/tmp/cargo-target \ | ||
--mount=type=bind,source=.,target=/tmp/build \ | ||
set -x && \ | ||
ls -la /drive-deposits && \ | ||
cd /tmp/build && \ | ||
mkdir -p /tmp/cargo-target && \ | ||
CARGO_TARGET_DIR=/tmp/cargo-target cargo build --package $APP_NAME --locked --release && \ | ||
echo "Contents of /tmp/cargo-target/release/ directory:" && \ | ||
ls -la /tmp/cargo-target/release/ && \ | ||
if [ -f /tmp/cargo-target/release/$APP_NAME ]; then \ | ||
mkdir -p /bin/server && \ | ||
cp /tmp/cargo-target/release/$APP_NAME /bin/server/$APP_NAME && \ | ||
echo "Contents of /bin/server directory:" && \ | ||
ls -la /bin/server; \ | ||
else \ | ||
echo "Binary $APP_NAME not found in /tmp/cargo-target/release/"; \ | ||
exit 1; \ | ||
fi | ||
|
||
################################################################################# | ||
# Create a new stage for running the application | ||
# could use distroless | ||
# FROM gcr.io/distroless/cc-debian11 | ||
# or slim | ||
# FROM debian:buster-slim | ||
# this is docker init by default | ||
FROM alpine:3.18 AS final | ||
|
||
WORKDIR /bin | ||
|
||
# Create a non-privileged user that the app will run under. | ||
# See https://docs.docker.com/go/dockerfile-user-best-practices/ | ||
ARG UID=10001 | ||
RUN adduser \ | ||
--disabled-password \ | ||
--gecos "" \ | ||
--home "/nonexistent" \ | ||
--shell "/sbin/nologin" \ | ||
--no-create-home \ | ||
--uid "${UID}" \ | ||
appuser | ||
USER appuser | ||
|
||
WORKDIR /bin | ||
|
||
COPY --from=build /bin/server/$APP_NAME . | ||
|
||
RUN echo "Contents of workdir /bin directory for drive-deposits-rest-gateway-server in final:" && \ | ||
ls -la /bin | ||
|
||
EXPOSE 3000 | ||
|
||
ENV RUST_LOG="drive_deposits_rest_types=debug,drive_deposits_proto_grpc_types=debug,drive_deposits_rest_gateway_server=debug" | ||
|
||
ENV GRPC_SERVER_ADDRESS="http://drive-deposits-grpc-server:50052" | ||
|
||
CMD ["/bin/drive-deposits-rest-gateway-server"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
services: | ||
drive-deposits-grpc-server: | ||
build: | ||
context: . | ||
target: final | ||
dockerfile: Dockerfile.for.compose.grpc | ||
ports: | ||
- "50052:50052" | ||
networks: | ||
- drive-deposits-network | ||
environment: | ||
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} | ||
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} | ||
- AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION} | ||
|
||
networks: | ||
drive-deposits-network: | ||
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
services: | ||
drive-deposits-rest-gateway-server: | ||
build: | ||
context: . | ||
target: final | ||
dockerfile: Dockerfile.for.compose.rest.gateway | ||
ports: | ||
- "3000:3000" | ||
networks: | ||
- drive-deposits-network | ||
|
||
networks: | ||
drive-deposits-network: | ||
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.