Skip to content

Commit

Permalink
add:init local setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajdip019 committed Oct 25, 2024
1 parent 0a769f3 commit 6b335b9
Show file tree
Hide file tree
Showing 14 changed files with 440 additions and 93 deletions.
Binary file modified .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ data
.env
.env.local
private_key.pem
.errorviz-version
.errorviz-version
skaffold.generated.yaml
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"chrono",
"deks",
"dotenv",
"flexauth",
"inhouse",
"jsonwebtoken",
"lettre",
Expand Down
52 changes: 11 additions & 41 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# syntax=docker/dockerfile:1

# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/go/dockerfile-reference/

# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7

ARG RUST_VERSION=1.77
ARG APP_NAME=inhouse-auth

Expand All @@ -16,19 +10,21 @@ FROM rust:${RUST_VERSION}-alpine AS dev
# Set the working directory
WORKDIR /app

# Install system dependencies
RUN apk add --no-cache musl-dev

# Install OpenSSL development libraries
RUN apk add --no-cache pkgconfig openssl-dev

# -lssl -lcrypto are required for the openssl crate
RUN apk add --no-cache openssl-libs-static
# Install system dependencies and required libraries for the build
RUN apk add --no-cache musl-dev pkgconfig openssl-dev openssl-libs-static

# Install cargo-watch for auto-reloading
RUN cargo install cargo-watch

# Copy the source code into the container
# Copy the Cargo.toml and Cargo.lock files separately to cache dependencies
COPY Cargo.toml Cargo.lock ./

# Create a dummy source file and build dependencies to cache them
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo build --release || true
RUN rm -rf src

# Copy the actual source code
COPY . .

# Mount the source code into the container
Expand Down Expand Up @@ -95,29 +91,3 @@ EXPOSE ${PORT}

# What the container should run when it is started.
CMD ["/bin/server"]


################################################################################
# Docker File for SMTP Server

FROM ubuntu:latest AS smtp

ARG EMAIL
ARG EMAIL_PASSWORD
ARG MAIL_NAME
ARG SMTP_DOMAIN
ARG SMTP_PORT

RUN apt-get update && \
apt-get install -y mailutils && \
apt install -y postfix

COPY /main.cf /etc/postfix/main.cf

RUN sh -c 'echo "root: ${EMAIL}" >> /etc/aliases' && \
sh -c 'echo "${MAIL_NAME}" >> /etc/mailname' && \
sh -c 'echo "[${SMTP_DOMAIN}]:${SMTP_PORT} ${EMAIL}:${EMAIL_PASSWORD}" >> /etc/postfix/sasl_passwd' && \
postmap /etc/postfix/sasl_passwd && \
chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db

CMD service postfix restart && tail -f /dev/null
22 changes: 22 additions & 0 deletions Dockerfile.smtp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Docker File for SMTP Server
FROM ubuntu:latest AS smtp

ARG EMAIL
ARG EMAIL_PASSWORD
ARG MAIL_NAME
ARG SMTP_DOMAIN
ARG SMTP_PORT

RUN apt-get update && \
apt-get install -y mailutils && \
apt install -y postfix

COPY /main.cf /etc/postfix/main.cf

RUN sh -c 'echo "root: ${EMAIL}" >> /etc/aliases' && \
sh -c 'echo "${MAIL_NAME}" >> /etc/mailname' && \
sh -c 'echo "[${SMTP_DOMAIN}]:${SMTP_PORT} ${EMAIL}:${EMAIL_PASSWORD}" >> /etc/postfix/sasl_passwd' && \
postmap /etc/postfix/sasl_passwd && \
chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db

CMD service postfix restart && tail -f /dev/null
4 changes: 3 additions & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ services:
- mongodb
- smtp-server
environment:
MONGO_URI: mongodb://admin:admin@mongodb:27017
MONGO_URI: mongodb
SERVER_KEK: ${SERVER_KEK}
EMAIL: ${EMAIL}
EMAIL_PASSWORD: ${EMAIL_PASSWORD}
MAIL_NAME: ${MAIL_NAME}
SMTP_DOMAIN: ${SMTP_DOMAIN}
SMTP_PORT: ${SMTP_PORT}
X_API_KEY: ${X_API_KEY}
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
volumes:
- ./src:/app/src

Expand Down
7 changes: 7 additions & 0 deletions k8s/flexauth-config-map.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: flexauth-config
namespace: flexauth
data:
database_url: mongodb-service
95 changes: 95 additions & 0 deletions k8s/flexauth-service-depl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: flexauth-server
namespace: flexauth
labels:
app: flexauth-server
spec:
replicas: 1
selector:
matchLabels:
app: flexauth-server
template:
metadata:
labels:
app: flexauth-server
spec:
containers:
- name: flexauth-server
image: flexauth-server:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
env:
- name: MONGO_URI
valueFrom:
configMapKeyRef:
name: flexauth-config
key: database_url
- name: PORT
valueFrom:
secretKeyRef:
name: flexauth-secrets
key: PORT
- name: SERVER_KEK
valueFrom:
secretKeyRef:
name: flexauth-secrets
key: SERVER_KEK
- name: EMAIL
valueFrom:
secretKeyRef:
name: flexauth-secrets
key: EMAIL
- name: EMAIL_PASSWORD
valueFrom:
secretKeyRef:
name: flexauth-secrets
key: EMAIL_PASSWORD
- name: MAIL_NAME
valueFrom:
secretKeyRef:
name: flexauth-secrets
key: MAIL_NAME
- name: SMTP_DOMAIN
valueFrom:
secretKeyRef:
name: flexauth-secrets
key: SMTP_DOMAIN
- name: SMTP_PORT
valueFrom:
secretKeyRef:
name: flexauth-secrets
key: SMTP_PORT
- name: X_API_KEY
valueFrom:
secretKeyRef:
name: flexauth-secrets
key: X_API_KEY
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: flexauth-secrets
key: MONGO_INITDB_ROOT_PASSWORD
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: flexauth-secrets
key: MONGO_INITDB_ROOT_USERNAME

---
apiVersion: v1
kind: Service
metadata:
name: flexauth-service
namespace: flexauth
spec:
type: NodePort
selector:
app: flexauth-server
ports:
- protocol: TCP
port: 8080
targetPort: 8080
nodePort: 30008
46 changes: 46 additions & 0 deletions k8s/mongodb-depl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb
namespace: flexauth
labels:
app: mongodb
spec:
replicas: 1
selector:
matchLabels:
app: mongodb
template:
metadata:
labels:
app: mongodb
spec:
containers:
- name: mongodb
image: mongo
ports:
- containerPort: 27017
env:
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: flexauth-secrets
key: MONGO_INITDB_ROOT_USERNAME
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: flexauth-secrets
key: MONGO_INITDB_ROOT_PASSWORD
---
apiVersion: v1
kind: Service
metadata:
name: mongodb-service
namespace: flexauth
spec:
selector:
app: mongodb
ports:
- protocol: TCP
port: 27017
targetPort: 27017
63 changes: 63 additions & 0 deletions k8s/mongodb-express-depl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb-express
namespace: flexauth
labels:
app: mongodb-express
spec:
replicas: 1
selector:
matchLabels:
app: mongodb-express
template:
metadata:
labels:
app: mongodb-express
spec:
containers:
- name: mongodb-express
image: mongo-express
ports:
- containerPort: 8081
env:
- name: ME_CONFIG_MONGODB_SERVER
valueFrom:
configMapKeyRef:
name: flexauth-config
key: database_url
- name: ME_CONFIG_MONGODB_ADMINUSERNAME
valueFrom:
secretKeyRef:
name: flexauth-secrets
key: MONGO_INITDB_ROOT_USERNAME
- name: ME_CONFIG_MONGODB_ADMINPASSWORD
valueFrom:
secretKeyRef:
name: flexauth-secrets
key: MONGO_INITDB_ROOT_PASSWORD
- name: ME_CONFIG_BASICAUTH_USERNAME
valueFrom:
secretKeyRef:
name: flexauth-secrets
key: MONGO_INITDB_ROOT_USERNAME
- name: ME_CONFIG_BASICAUTH_PASSWORD
valueFrom:
secretKeyRef:
name: flexauth-secrets
key: MONGO_INITDB_ROOT_PASSWORD
---
apiVersion: v1
kind: Service
metadata:
name: mongodb-express-service
namespace: flexauth
spec:
selector:
app: mongodb-express
type: LoadBalancer
ports:
- protocol: TCP
port: 8081
targetPort: 8081
nodePort: 30000
Loading

0 comments on commit 6b335b9

Please sign in to comment.