diff --git a/README.md b/README.md new file mode 100644 index 0000000..dffcf90 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# Container Dashboard +A simple dashboard for turning your docker/kubernetes services (containers/pods) on or off from a web UI + +## Usage +First build the docker images under `frontend` and `backend` + +`docker build -t container-dashboard-frontend ./frontend` + +`docker build -t container-dashboard-backend ./backend` + +### Frontend +Run the frontend with `docker run -d -p 80:80 BACKEND=\ container-dashboard-frontend:latest`. + +`BACKEND` points towards the backend container and looks something like this: `http(s)://123.123.123:8080` + +### Backend +Run the backend with `docker run -d -p 8080:8080 -e BACKEND= -e KUBECONFIG= -v /path/to/kube-config:/app/kube-config container-dashboard-backend:latest` + +The environment variable `KUBECONFIG` and the mounted kubernetes config folder are only needed if you are using kubernetes. + +Docker backend has not been implemented yet. Feel free to contribute ^w^ diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..0498971 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,28 @@ +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS backend-build + +WORKDIR /app/backend + +# Copy backend files +COPY ./*.csproj ./ +RUN dotnet restore + +COPY ./ ./ +RUN dotnet publish -c Release -o out + +FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime + +WORKDIR /app + +# Copy backend build output +COPY --from=backend-build /app/backend/out ./backend + +# Create a directory for the Kubernetes configuration file +RUN mkdir -p /app/kube-config + +# Set an environment variable to point to the Kubernetes config directory +ENV KUBECONFIG=/app/kube-config/config +ENV BACKEND=kubernetes + +EXPOSE 8080 + +CMD ["sh", "-c", "dotnet backend/backend.dll"] \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..1b26e71 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,22 @@ +FROM node:18 AS frontend-build + +WORKDIR /app/frontend + +COPY ./package.json ./package-lock.json ./ +RUN npm install + +COPY ./ ./ +RUN npm run build + +FROM nginx:stable AS runtime + +WORKDIR /usr/share/nginx/html + +COPY --from=frontend-build /app/frontend/dist . +COPY ./envVars.sh /docker-entrypoint.d/ + +RUN chmod +x /docker-entrypoint.d/envVars.sh + +ENV BACKEND= + +EXPOSE 80 \ No newline at end of file diff --git a/frontend/envVars.sh b/frontend/envVars.sh new file mode 100755 index 0000000..10ac347 --- /dev/null +++ b/frontend/envVars.sh @@ -0,0 +1,5 @@ +SETTINGFILE=`find /usr/share/nginx/html/_astro/ -name 'CardList.*.js'` + +echo "Setting backend in $SETTINGFILE to $BACKEND" + +sed -i "s#ENDPOINT#$BACKEND#g" $SETTINGFILE \ No newline at end of file diff --git a/frontend/src/Lib/Config.ts b/frontend/src/Lib/Config.ts index 22f4d4f..366d882 100644 --- a/frontend/src/Lib/Config.ts +++ b/frontend/src/Lib/Config.ts @@ -3,5 +3,5 @@ export interface ConfigType { } export const Config: ConfigType = { - endpoint: "http://localhost:5107/Service", + endpoint: "ENDPOINT/Service", } \ No newline at end of file