Skip to content

Commit

Permalink
chore: add docker
Browse files Browse the repository at this point in the history
  • Loading branch information
opeolluwa committed Sep 24, 2024
1 parent a758244 commit a75c176
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .dockerignore
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
65 changes: 65 additions & 0 deletions Dockerfile
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"]
38 changes: 38 additions & 0 deletions compose.yaml
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:


0 comments on commit a75c176

Please sign in to comment.