Dockerhub integration

This commit is contained in:
Eduardo Silva 2024-04-08 17:32:56 -03:00
parent 03f027f100
commit ab908887e4
9 changed files with 294 additions and 66 deletions

17
.env.example Normal file
View file

@ -0,0 +1,17 @@
# Configure SERVER_ADDRESS to match the address of the server. If you don't have a DNS name, you can use the IP address.
# A missconfigured SERVER_ADDRESS will cause the app to have CSRF errors.
SERVER_ADDRESS=my_server_address
DEBUG_MODE=False
# Choose a timezone from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
TIMEZONE=America/Sao_Paulo
# Available options are 'sqlite', 'postgres'
DATABASE_ENGINE=postgres
# If you want to use sqlite or postgres outside of docker, you should use docker-compose-no-postgres.yml
# and provide POSTGRES_HOST, POSTGRES_PORT below.
#POSTGRES_HOST=${POSTGRES_HOST}
#POSTGRES_PORT=${POSTGRES_PORT}
POSTGRES_DB=routerfleet
POSTGRES_USER=routerfleet
POSTGRES_PASSWORD=your_database_password

130
README.md
View file

@ -31,101 +31,127 @@ Manage users and their permissions to ensure secure access to RouterFleet.
![User Management](screenshots/user-manager.png) ![User Management](screenshots/user-manager.png)
## Getting Started ## Deployment Instructions
To get started with RouterFleet, you'll want to clone the repository and set up your environment. Here's a quick guide: These steps will guide you through deploying the RouterFleet project:
### Step 1: Clone the Repository ### Step 1: Prepare the Environment
First, clone the RouterFleet repository to your local machine or server: Create a dedicated directory for the RouterFleet project and navigate into it. This directory will serve as your working environment for the deployment.
```bash ```bash
git clone https://github.com/eduardogsilva/routerfleet.git mkdir routerfleet && cd routerfleet
cd routerfleet
``` ```
### Step 2: Deploy with Docker ### Step 2: Fetch the Docker Compose File
Use the following command to start your RouterFleet server. This command will also build the Docker image if it's the first time you're running it, or if there have been changes to the Dockerfile: Download the appropriate `docker-compose.yml` file directly into your working directory to ensure you're using the latest deployment configuration. Choose one of the following based on your deployment scenario:
#### With Postgres (default setup)
This is the recommended setup for production environments. Download the `docker-compose.yml` that includes the Postgres database container:
```bash ```bash
SERVER_ADDRESS=yourserver.example.com POSTGRES_PASSWORD=your_password TIMEZONE=America/Sao_Paulo docker compose up --build -d wget -O docker-compose.yml https://raw.githubusercontent.com/eduardogsilva/routerfleet/main/docker-compose.yml
``` ```
[Timezone List](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
During the deployment, a self-signed certificate will be automatically generated for use with HTTPS. If you prefer to use your own certificates, proceed to the next step. #### Without Postgres (sqlite or remote database)
### Step 3: Update SSL Certificates (Optional) If you prefer to use SQLite or a remote database, download the `docker-compose-no-postgres.yml` file:
If you have your own SSL certificates and wish to use them instead of the self-signed certificate, follow these instructions: ```bash
wget -O docker-compose.yml https://raw.githubusercontent.com/eduardogsilva/routerfleet/main/docker-compose-no-postgres.yml
```
- Navigate to the certificates volume. ### Step 3: Create the `.env` File
- Replace `nginx.pem` and `nginx.key` with your certificate and key files, respectively.
**Note:** If your server does not have a DNS name and you're using an IP address, set the `SERVER_ADDRESS` variable to your server's IP address (`SERVER_ADDRESS=ip_address`). Generate a `.env` file in the same directory as your `docker-compose.yml` with the necessary environment variables:
### Step 4: Access the Web Interface ```env
# Configure SERVER_ADDRESS to match the address of the server. If you don't have a DNS name, you can use the IP address.
# A missconfigured SERVER_ADDRESS will cause the app to have CSRF errors.
SERVER_ADDRESS=my_server_address
DEBUG_MODE=False
# Choose a timezone from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
TIMEZONE=America/Sao_Paulo
Open a web browser and navigate to `https://yourserver.example.com` to access the RouterFleet web interface. # Available options are 'sqlite', 'postgres'
DATABASE_ENGINE=postgres
# If you want to use sqlite or postgres outside of docker, you should use docker-compose-no-postgres.yml
# and provide POSTGRES_HOST, POSTGRES_PORT below.
#POSTGRES_HOST=${POSTGRES_HOST}
#POSTGRES_PORT=${POSTGRES_PORT}
POSTGRES_DB=routerfleet
POSTGRES_USER=routerfleet
POSTGRES_PASSWORD=your_database_password
```
**Important:** If you are using the self-signed certificate, your browser will present a certificate exception warning. You must accept this exception to proceed to the RouterFleet interface. Adjust the variables according to your setup.
### Step 4: Run Docker Compose
Launch your RouterFleet deployment with the Docker Compose command:
```bash
docker compose up -d
```
### Step 5: Update SSL Certificates (Optional)
If you prefer to use your own SSL certificates instead of the auto-generated self-signed certificate:
- Access the `certificates` volume.
- Replace `nginx.pem` and `nginx.key` with your certificate files.
### Step 6: Access the Web Interface
Visit `https://yourserver.example.com` in your web browser to access the RouterFleet web interface. Remember, if you're using the self-signed certificate, you'll need to accept the certificate exception in your browser.
Following these steps will set up RouterFleet on your server, ensuring you're utilizing the latest configurations for optimal performance and security.
## Upgrade Instructions for RouterFleet ## Upgrade Instructions for RouterFleet
To maintain security, performance, and access to new features in RouterFleet, it's important to follow these steps when upgrading: To maintain security, performance, and access to new features in RouterFleet, it's important to follow these steps when upgrading:
1.**Backup Database**
### Step 1: Prepare the Environment
Begin by navigating to your routerfleet directory:
```bash
cd path/to/routerfleet
```
If you're upgrading from an existing git clone installation, navigate to your current project directory.
```bash
cd /path/to/routerfleet_git_clone
```
### Step 2: Backup Database
Before starting the upgrade, it's crucial to back up your database. This step ensures you can revert to the previous state if the upgrade encounters problems. For the database, we recommend manually running a `pg_dump` command to create a backup. Before starting the upgrade, it's crucial to back up your database. This step ensures you can revert to the previous state if the upgrade encounters problems. For the database, we recommend manually running a `pg_dump` command to create a backup.
```bash ```bash
docker exec -e PGPASSWORD=your_password routerfleet-postgres pg_dump -U routerfleet -d routerfleet > /root/routerfleet-$(date +%Y-%m-%d-%H%M%S).sql docker exec -e PGPASSWORD=your_password routerfleet-postgres pg_dump -U routerfleet -d routerfleet > /root/routerfleet-$(date +%Y-%m-%d-%H%M%S).sql
``` ```
2.**Preparation:** ### Step 3: Shutdown Services
Navigate to your RouterFleet directory on your machine or server:
```bash
cd path/to/routerfleet
```
3.**Shutdown Services:**
Prevent data loss by stopping all RouterFleet services gracefully: Prevent data loss by stopping all RouterFleet services gracefully:
```bash ```bash
docker compose down docker compose down
``` ```
### Step 4: Deploy using Docker Compose
Follow the previously outlined [Deployment Instructions](#deployment-instructions).
4.**Fetch the Latest Updates:** Don't forget to update the `docker-compose.yml` file to the latest version by re-downloading it from the repository.
Update your local repository to get the latest RouterFleet version: ### Post-Upgrade Checks
```bash
git pull origin main
```
5.**Deploy the Updated Version:** - **Verify Operation:** After the services start, access the web interface to ensure routerfleet functions as expected. Examine the application logs for potential issues.
- **Support and Troubleshooting:** For any complications or need for further information, consult the project's [Discussions](https://github.com/eduardogsilva/routerfleet/discussions) page or relevant documentation.
With the latest updates in place, re-deploy RouterFleet using Docker Compose. This step rebuilds the Docker image to incorporate any changes:
```bash
SERVER_ADDRESS=yourserver.example.com POSTGRES_PASSWORD=your_password TIMEZONE=America/Sao_Paulo docker compose up --build -d
```
6.**Verify Operation:**
After restarting the services, check the RouterFleet web interface to ensure all functions are operating correctly. Examine the application logs for errors or warnings:
```bash
docker compose logs
```
7.**Post-Upgrade Checks:**
- Review the application and system logs carefully for any anomalies.
- If you encounter any issues, consider reporting them on [GitHub Issues](https://github.com/eduardogsilva/routerfleet/issues) or seek advice in [Discussions](https://github.com/eduardogsilva/routerfleet/discussions). If necessary, revert to your earlier backup.
Following these instructions will help ensure a smooth upgrade process for your RouterFleet installation, keeping it secure and efficient. Following these instructions will help ensure a smooth upgrade process for your RouterFleet installation, keeping it secure and efficient.
## Contributing ## Contributing
As an open source project, RouterFleet thrives on community support. Whether you're a developer, a network engineer, or just someone interested in network management, there are many ways you can contribute: As an open source project, RouterFleet thrives on community support. Whether you're a developer, a network engineer, or just someone interested in network management, there are many ways you can contribute:

37
build_and_push.sh Executable file
View file

@ -0,0 +1,37 @@
#!/bin/bash
IMAGES=(
"eduardosilva/routerfleet:latest"
"eduardosilva/routerfleet-monitoring:latest"
"eduardosilva/routerfleet-nginx:latest"
"eduardosilva/routerfleet-cron:latest"
)
build_images() {
echo "Starting the build of the images..."
docker compose -f docker-compose-build.yml build
if [ $? -eq 0 ]; then
echo "Build completed successfully."
else
echo "Error during the image build."
exit 1
fi
}
push_images() {
for IMAGE in "${IMAGES[@]}"; do
echo "Pushing image: $IMAGE..."
docker push "$IMAGE"
if [ $? -eq 0 ]; then
echo "$IMAGE pushed successfully."
else
echo "Error pushing the image: $IMAGE"
exit 1
fi
done
}
build_images
push_images
echo "Build and push operations completed successfully."

View file

@ -1,6 +1,7 @@
FROM nginx:alpine FROM nginx:alpine
RUN apk --no-cache add openssl RUN apk --no-cache add openssl
COPY nginx_entrypoint.sh /nginx_entrypoint.sh COPY nginx_entrypoint.sh /nginx_entrypoint.sh
COPY virtualhost.conf /etc/nginx/conf.d/default.conf
RUN chmod +x /nginx_entrypoint.sh RUN chmod +x /nginx_entrypoint.sh
ENTRYPOINT ["/nginx_entrypoint.sh"] ENTRYPOINT ["/nginx_entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"] CMD ["nginx", "-g", "daemon off;"]

24
docker-compose-build.yml Normal file
View file

@ -0,0 +1,24 @@
version: '3'
services:
routerfleet:
image: eduardosilva/routerfleet:latest
build:
context: .
routerfleet-cron:
image: eduardosilva/routerfleet-cron:latest
build:
context: ./containers/cron
dockerfile: Dockerfile-cron
routerfleet-monitoring:
image: eduardosilva/routerfleet-monitoring:latest
build:
context: ./containers/monitoring
dockerfile: Dockerfile-monitoring
routerfleet-nginx:
image: eduardosilva/routerfleet-nginx:latest
build:
context: ./containers/nginx
dockerfile: Dockerfile-nginx

77
docker-compose-dev.yml Normal file
View file

@ -0,0 +1,77 @@
services:
routerfleet-postgres:
container_name: routerfleet-postgres
restart: unless-stopped
image: postgres:latest
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
routerfleet:
container_name: routerfleet
restart: unless-stopped
build:
context: .
environment:
- SERVER_ADDRESS=${SERVER_ADDRESS}
- DEBUG_MODE=${DEBUG_MODE}
- DATABASE_ENGINE=${DATABASE_ENGINE}
- POSTGRES_HOST=${POSTGRES_HOST}
- POSTGRES_PORT=${POSTGRES_PORT}
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- TIMEZONE=${TIMEZONE}
- COMPOSE_TYPE=with-postgres
volumes:
- sqlite_volume:/var/lib/routerfleet_sqlite/
- media_root:/var/lib/routerfleet/
- static_volume:/app_static_files/
command: /bin/bash /app/init.sh
depends_on:
- routerfleet-postgres
routerfleet-cron:
container_name: routerfleet-cron
restart: unless-stopped
build:
context: ./containers/cron
dockerfile: Dockerfile-cron
depends_on:
- routerfleet
routerfleet-monitoring:
container_name: routerfleet-monitoring
restart: unless-stopped
build:
context: ./containers/monitoring
dockerfile: Dockerfile-monitoring
depends_on:
- routerfleet
routerfleet-nginx:
container_name: routerfleet-nginx
restart: unless-stopped
image: nginx:alpine
build:
context: ./containers/nginx
dockerfile: Dockerfile-nginx
volumes:
- static_volume:/static
- https_cert:/certificate
ports:
- "80:80"
- "443:443"
depends_on:
- routerfleet
volumes:
static_volume:
https_cert:
media_root:
postgres_data:
sqlite_volume:

View file

@ -0,0 +1,55 @@
services:
routerfleet:
container_name: routerfleet
restart: unless-stopped
image: eduardosilva/routerfleet:latest
environment:
- SERVER_ADDRESS=${SERVER_ADDRESS}
- DEBUG_MODE=${DEBUG_MODE}
- DATABASE_ENGINE=${DATABASE_ENGINE}
- POSTGRES_HOST=${POSTGRES_HOST}
- POSTGRES_PORT=${POSTGRES_PORT}
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- TIMEZONE=${TIMEZONE}
- COMPOSE_TYPE=no-postgres
volumes:
- sqlite_volume:/var/lib/routerfleet_sqlite/
- media_root:/var/lib/routerfleet/
- static_volume:/app_static_files/
command: /bin/bash /app/init.sh
routerfleet-cron:
container_name: routerfleet-cron
restart: unless-stopped
image: eduardosilva/routerfleet-cron:latest
depends_on:
- routerfleet
routerfleet-monitoring:
container_name: routerfleet-monitoring
restart: unless-stopped
image: eduardosilva/routerfleet-monitoring:latest
depends_on:
- routerfleet
routerfleet-nginx:
container_name: routerfleet-nginx
restart: unless-stopped
image: eduardosilva/routerfleet-nginx:latest
volumes:
- static_volume:/static
- https_cert:/certificate
ports:
- "80:80"
- "443:443"
depends_on:
- routerfleet
volumes:
static_volume:
https_cert:
media_root:
postgres_data:
sqlite_volume:

View file

@ -13,8 +13,7 @@ services:
routerfleet: routerfleet:
container_name: routerfleet container_name: routerfleet
restart: unless-stopped restart: unless-stopped
build: image: eduardosilva/routerfleet:latest
context: .
environment: environment:
- SERVER_ADDRESS=${SERVER_ADDRESS} - SERVER_ADDRESS=${SERVER_ADDRESS}
- DEBUG_MODE=${DEBUG_MODE} - DEBUG_MODE=${DEBUG_MODE}
@ -26,7 +25,6 @@ services:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- TIMEZONE=${TIMEZONE} - TIMEZONE=${TIMEZONE}
- COMPOSE_TYPE=with-postgres - COMPOSE_TYPE=with-postgres
volumes: volumes:
- sqlite_volume:/var/lib/routerfleet_sqlite/ - sqlite_volume:/var/lib/routerfleet_sqlite/
- media_root:/var/lib/routerfleet/ - media_root:/var/lib/routerfleet/
@ -38,28 +36,21 @@ services:
routerfleet-cron: routerfleet-cron:
container_name: routerfleet-cron container_name: routerfleet-cron
restart: unless-stopped restart: unless-stopped
build: image: eduardosilva/routerfleet-cron:latest
context: ./containers/cron
dockerfile: Dockerfile-cron
depends_on: depends_on:
- routerfleet - routerfleet
routerfleet-monitoring: routerfleet-monitoring:
container_name: routerfleet-monitoring container_name: routerfleet-monitoring
restart: unless-stopped restart: unless-stopped
build: image: eduardosilva/routerfleet-monitoring:latest
context: ./containers/monitoring
dockerfile: Dockerfile-monitoring
depends_on: depends_on:
- routerfleet - routerfleet
routerfleet-nginx: routerfleet-nginx:
container_name: routerfleet-nginx container_name: routerfleet-nginx
restart: unless-stopped restart: unless-stopped
image: nginx:alpine image: eduardosilva/routerfleet-nginx:latest
build:
context: ./containers/nginx
dockerfile: Dockerfile-nginx
volumes: volumes:
- static_volume:/static - static_volume:/static
- https_cert:/certificate - https_cert:/certificate

View file

@ -140,6 +140,6 @@ STATICFILES_DIRS = [
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
MEDIA_ROOT = '/var/lib/routerfleet/' MEDIA_ROOT = '/var/lib/routerfleet/'
ROUTERFLEET_VERSION = 7004 ROUTERFLEET_VERSION = 7005
from routerfleet.production_settings import * from routerfleet.production_settings import *