Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jonathanxdr/m347
Dienst mit Container anwenden
https://github.com/jonathanxdr/m347
Last synced: 7 days ago
JSON representation
Dienst mit Container anwenden
- Host: GitHub
- URL: https://github.com/jonathanxdr/m347
- Owner: JonathanXDR
- License: mit
- Created: 2023-03-02T13:18:49.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-25T21:51:15.000Z (7 months ago)
- Last Synced: 2024-04-25T23:44:36.992Z (7 months ago)
- Language: Vue
- Homepage:
- Size: 652 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# M347
Welcome to M347-Portfolio, a ToDo application built using Docker and Kubernetes. This README provides documentation on how to set up, manage, and debug the application. The application consists of a frontend, backend, and a MariaDB database.
## Table of Contents
- [M347-Portfolio](#m347-portfolio)
- [Table of Contents](#table-of-contents)
- [Prerequisites](#prerequisites)
- [Getting Started](#getting-started)
- [Using Docker](#using-docker)
- [Build Images](#build-images)
- [Manage Containers (Docker Compose)](#manage-containers-docker-compose)
- [Debugging](#debugging)
- [Using Kubernetes](#using-kubernetes)
- [Manage Resources](#manage-resources)
- [Debugging](#debugging-1)
- [Additional Information](#additional-information)
- [Environment Variables](#environment-variables)
- [GitHub Actions](#github-actions)## Prerequisites
Before you begin, ensure you have the following tools & services installed on your local machine:
- [Docker](https://docs.docker.com/get-docker/) - Used for running and building the application.
- [Kubernetes (Kubectl)](https://kubernetes.io/docs/tasks/tools/) - Used for managing the application in a Kubernetes cluster (Local or Cloud).
- [Minikube](https://minikube.sigs.k8s.io/docs/start/) - Used for running a local Kubernetes cluster.## Getting Started
## Using Docker
### Build Images
Normally, the Docker images for the frontend and backend are built using [GitHub Actions](#github-actions), when pushing a commit to the `main` branch. However, you can also build the Docker images locally using the following commands:
```bash
docker build -t ./
```### Manage Containers (Docker Compose)
For running the application locally quickly, you can use Docker Compose. This will create & run the Docker containers for the frontend, backend, and MariaDB database. To start the application, run the following command:
```bash
docker-compose up -d
```To stop the application, run the following command:
```bash
docker-compose down
```### Debugging
Here are some useful docker commands for debugging:
```bash
# 1. List all running containers, including their IDs, names, and statuses.
docker ps# 2. Show the logs of a specific container, which can help you find error messages or trace the application's execution.
docker logs# 3. Execute a command inside a running container, such as running a shell (`/bin/bash` or `/bin/sh`) to investigate the container's file system and processes.
docker exec -it# 4. Provide detailed information about a container, including its configuration, network settings, and mounted volumes.
docker inspect# 5. Display real-time performance statistics for all running containers, including CPU usage, memory consumption, and network I/O.
docker stats# 6. Show the running processes inside a container, similar to the `top` command on Linux.
docker top# 7. List the file system changes made in a container compared to the base image.
docker diff# 8. Copy files or directories between a container and the local file system, which can be helpful for examining application data or configuration files.
docker cp :# 9. If you are using Docker Compose, show the logs for all services defined in the `docker-compose.yml` file.
docker-compose logs#10. Tear down the current services and rebuild the containers from scratch if you've made changes to your application's code or dependencies.
docker-compose down && docker-compose up --build
```## Using Kubernetes
For running the application locally, you can use Minikube. This will create the Kubernetes cluster. To start Minikube, run the following command:
```bash
minikube start
```To stop Minikube again, run:
```bash
minikube stop
```### Manage Resources
After the Kubernetes cluster was created, you can apply the Kubernetes resources for the application using the following commands.
```bash
kubectl apply -f .
```To delete the Kubernetes resources, use the `delete` keyword instead of `apply`.
### Debugging
Here are some useful kubectl commands for debugging:
```bash
# 1. Get information about all resources in the cluster (e.g., pods, services, deployments)
kubectl get# 2. Describe a specific resource in detail
kubectl describe# 3. Get logs from a specific pod
kubectl logs# 4. Stream logs from a specific pod in real-time
kubectl logs -f# 5. Get the current state of a Kubernetes configuration
kubectl config view# 6. Switch between different Kubernetes contexts
kubectl config use-context# 7. Execute a command within a specific pod
kubectl exec -it --# 8. Get the current status of a specific deployment
kubectl rollout status deployment/# 9. Display the history of a specific deployment
kubectl rollout history deployment/# 10. Get resource usage information for each pod in the namespace
kubectl top pod# 11. Get resource usage information for each node in the cluster
kubectl top node# 12. Debug issues with ingress by displaying ingress resources
kubectl get ingress```
## Additional Information
### Environment Variables
The application uses the following environment variables:
```bash
DB_HOST # The hostname of the MariaDB database server.
DB_USER # The username to use for connecting to the MariaDB database.
DB_PASSWORD # The password to use for connecting to the MariaDB database.
DB_NAME # The name of the MariaDB database to use.
```These environment variables can be set in the respective Docker and Kubernetes configuration files.
### GitHub Actions
`publish.yml`, is responsible for building and publishing Docker images for the frontend and backend components of the application. The action is triggered on each push to the repository.
The `publish.yml` file is composed of two jobs: `publish-frontend-image` and `publish-backend-image`. Both jobs have similar steps:
1. Check out the repository using the `actions/checkout@v2` action.
2. Log in to the GitHub Container Registry using the `docker/login-action@v1` action, with the `GHCR_PAT` secret for authentication.
3. Build the Docker image for either the frontend or backend, tagging it with the appropriate path in the GitHub Container Registry (e.g., `ghcr.io/jonathanxdr/todo-frontend:latest` or `ghcr.io/jonathanxdr/todo-backend:latest`).
4. Push the built image to the GitHub Container Registry.This GitHub Action allows for automated building and publishing of the Docker images, ensuring that the latest versions are always available in the GitHub Container Registry.