-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
135 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# 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 | ||
**/.gitignore | ||
**/.project | ||
**/.settings | ||
**/.toolstarget | ||
**/.vs | ||
**/.vscode | ||
**/*.*proj.user | ||
**/*.dbmdl | ||
**/*.jfm | ||
**/charts | ||
**/docker-compose* | ||
**/compose* | ||
**/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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
ARG RUST_VERSION=1.79.0 | ||
ARG APP_NAME=rustapi | ||
|
||
################################################################################ | ||
# Create a stage for building the application. | ||
|
||
FROM rust:${RUST_VERSION}-alpine AS build | ||
|
||
ARG APP_NAME | ||
|
||
# Adding necessary packages | ||
RUN apk update | ||
RUN apk add pkgconfig openssl openssl-dev musl-dev | ||
|
||
# Build the application. | ||
RUN rustup target add x86_64-unknown-linux-musl | ||
|
||
# copy the source | ||
WORKDIR /app | ||
COPY . . | ||
|
||
RUN cargo build --target=aarch64-unknown-linux-musl --release | ||
|
||
# RUN strip ./target/release/aarch64-unknown-linux-musl/$APP_NAME | ||
|
||
# RUN cp ./target/release/aarch64-unknown-linux-musl/$APP_NAME /bin/server | ||
|
||
################################################################################ | ||
# Create a new stage for running the application that contains the minimal | ||
# runtime dependencies for the application. This often uses a different base | ||
# image from the build stage where the necessary files are copied from the build | ||
# stage. | ||
# | ||
# The example below uses the alpine image as the foundation for running the app. | ||
# By specifying the "3.18" tag, it will use version 3.18 of alpine. If | ||
# reproducability is important, consider using a digest | ||
# (e.g., alpine@sha256:664888ac9cfd28068e062c991ebcff4b4c7307dc8dd4df9e728bedde5c449d91). | ||
|
||
FROM alpine:latest AS final | ||
|
||
WORKDIR /app | ||
RUN cd /app | ||
# 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 | ||
|
||
# Copy the executable from the "build" stage. | ||
COPY --from=build /app/target/release/$APP_NAME /bin/server | ||
|
||
# Expose the port that the application listens on. | ||
EXPOSE 3000 | ||
|
||
# What the container should run when it is started. | ||
CMD ["/bin/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,38 @@ | ||
version: "3" | ||
|
||
services: | ||
app: | ||
build: | ||
context: . | ||
target: final | ||
ports: | ||
- 3000:3000 | ||
environment: | ||
- PORT=3000 | ||
- DB_CONNECTION_URL = postgres://rustapi:RAa6dHNblVoJboG6fyFlbCvlYe7@database | ||
|
||
depends_on: | ||
database: | ||
condition: service_started | ||
# the DB | ||
database: | ||
image: postgres:15-alpine | ||
restart: always | ||
shm_size: 100mb | ||
volumes: | ||
- db-data:/var/lib/postgresql/data | ||
environment: | ||
- POSTGRES_DB=rustapi.db | ||
- POSTGRES_USER=rustapi | ||
- POSTGRES_PASSWORD=RAa6dHNblVoJboG6fyFlbCvlYe7 | ||
expose: | ||
- 5432 | ||
healthcheck: | ||
test: [ "CMD", "pg_isready -d rustapi.db rustapi"] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 | ||
volumes: | ||
db-data: | ||
|
||
|