Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Kubernetes #179

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions gym-app.code-workspace

This file was deleted.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
"ci": "pnpm install --frozen-lockfile",
"mongo-logs": "docker compose logs -f mongo1 | grep -oP '\"\\$date\":\"\\K[^\"]+|\"msg\":\"\\K[^\"]+' | sed -n 'N;s/\\n/ - /p'",
"mongo-logs-health": "docker inspect --format='{{json .State.Health}}' gym-mongo1-1 | jq",
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org thomfilgcom --project node ./build && sentry-cli sourcemaps upload --org thomfilgcom --project node ./build"
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org thomfilgcom --project node ./build && sentry-cli sourcemaps upload --org thomfilgcom --project node ./build",
"kompose:convert:dev": "npm run docker:compose:merge:dev && kompose convert -f ./kubernetes/docker-compose.dev.yml --out kubernetes/dev",
"kompose:convert:prod": "npm run docker:compose:merge:prod && kompose convert -f ./kubernetes/docker-compose.prod.yml --out kubernetes/prod",
"docker:compose:merge:prod": "docker-compose -f docker-compose.yml -f docker-compose.prod.yml config > ./kubernetes/docker-compose.prod.yml",
"docker:compose:merge:dev": "docker-compose -f docker-compose.yml -f docker-compose.override.yml config > ./kubernetes/docker-compose.dev.yml"
},
"dependencies": {
"@emotion/react": "^11.13.0",
Expand Down
16 changes: 9 additions & 7 deletions scripts/init-repository.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ source ./scripts/setup/doppler.sh
source ./scripts/setup/mongo.sh
source ./scripts/setup/nvm.sh
source ./scripts/setup/pnpm.sh

source ./scripts/setup/kompose.sh
source ./scripts/setup/kubernetes.sh

# Ensure .nvmrc is available
if [[ ! -f ".nvmrc" ]]; then
Expand All @@ -16,20 +17,21 @@ fi
installDocker
installDockerCompose
installDoppler

configureDoppler
installKubernetes
installKompose
installNVM
installPnpm

pnpm install

# Check if .env file exists
if [[ ! -f .env ]]; then
# If not, copy .env.sample to .env
cp .env.sample .env
fi

configureDoppler

pnpm install

genMongoKeyFile

# Use Doppler to run Docker Compose
doppler run -- docker compose up --build -d
pnpm dev -d
16 changes: 16 additions & 0 deletions scripts/setup/kompose.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

installKompose() {
# Install Kompose if not already installed
if ! command -v kompose &> /dev/null
then
echo "Kompose not found! Installing..."
curl -L https://github.com/kubernetes/kompose/releases/download/v1.34.0/kompose-linux-amd64 -o kompose
chmod +x kompose
sudo mv kompose /usr/local/bin/kompose
else
echo "Kompose is already installed!"
fi
kompose version
}

35 changes: 35 additions & 0 deletions scripts/setup/kubernetes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Function to create MongoDB secrets
createSecrets() {
if kubectl get secret mongo-secret &> /dev/null; then
echo "Secret mongo-secret already exists"
else
echo "Creating mongo-secret"
export $(grep -v '^#' .env | xargs)
kubectl create secret generic mongo-secret \
--from-literal=mongo-root-username=$MONGO_INITDB_ROOT_USERNAME \
--from-literal=mongo-root-password=$MONGO_INITDB_ROOT_PASSWORD
fi
}

installKubernetes() {
# Install kubectl if not already installed
if ! command -v kubectl &> /dev/null
then
echo "kubectl not found! Installing..."
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
if [[ -f ./kubectl ]]; then
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
echo "kubectl installed successfully!"
else
echo "Failed to download kubectl."
exit 1
fi
else
echo "kubectl is already installed!"
fi

kubectl version --client
}