Deployment Overview of Gitea on Server¶
Prerequisites and Basic Requirements¶
The deployment requires a Linux server running Ubuntu with root privileges. The system must have Docker and Docker Compose installed to manage the containerized application. The following ports must be available and open on the server firewall:
- Port
3000for the Gitea web interface. - Port
22for SSH access to the Gitea instance. - Ports
80and443for the Nginx reverse proxy and SSL termination.
A valid domain name is required to configure the Nginx proxy and obtain SSL certificates via Certbot.
File and Directory Structure¶
The application and its supporting services utilize the following directory structure on the host system:
/opt/gitea: Contains the Docker Compose configuration file for the Gitea service./data/gitea: The primary data directory for Gitea, storing repositories, configuration files, and logs./root/nginx: Contains the Docker Compose configuration for the Nginx proxy and Certbot./data/nginx/user_conf.d: Stores custom Nginx configuration files for specific host keys./data/nginx/nginx-certbot.env: Environment file containing configuration for the Certbot service./etc/timezoneand/etc/localtime: System files configured toEurope/Moscowfor consistent timekeeping.
Application Installation Process¶
The Gitea application is deployed using Docker Compose. The installation process involves creating the necessary directories and generating the docker-compose.yml file within /opt/gitea. The configuration specifies the following:
- Image:
gitea/giteawith a specific version tag. - Container Name:
gitea. - Environment Variables:
USER_UID=1000USER_GID=1000- Restart Policy:
always. - Network: A dedicated internal network named
gitea. - Volume Mounts:
- The host directory
{{ gitea_data_dir }}is mounted to/datainside the container. - Host timezone files are mounted read-only to
/etc/timezoneand/etc/localtime. - Port Mapping:
- Host port
{{ gitea_port }}maps to container port3000. - Host port
{{ gitea_ssh_port }}maps to container port22.
The timezone is explicitly set to Europe/Moscow by copying the timezone file and creating a symbolic link for the local time.
Docker Containers and Their Deployment¶
Two primary Docker Compose setups are utilized for the deployment:
-
Gitea Service: The Gitea container is managed via the
docker-compose.ymlfile located in/opt/gitea. The service is started using the commanddocker-compose up -dexecuted from the/opt/giteadirectory. The container is configured to restart automatically upon failure or system reboot. -
Nginx and Certbot Service: A separate Docker Compose configuration is generated and stored in
/root/nginx/compose.yml. This setup includes:- Image:
jonasal/nginx-certbot:latest. - Restart Policy:
unless-stopped. - Network Mode:
host. - Volumes:
nginx_secrets(external volume) mounted to/etc/letsencrypt./data/nginx/user_conf.dmounted to/etc/nginx/user_conf.d.- Environment: Configured via
/data/nginx/nginx-certbot.envand includes the email[email protected]for certificate notifications.
- Image:
The Nginx service is started using docker compose up -d from the /root/nginx directory.
Proxy Servers¶
The deployment utilizes an Nginx reverse proxy container to handle incoming traffic and SSL termination. The proxy configuration is managed through the nginx-certbot image.
- Configuration Location: Custom host configurations are stored in
/data/nginx/user_conf.d. - Proxy Pass: The Nginx configuration is updated to forward requests to the Gitea container running on the host. The specific directive added is: This line is inserted into the
location /block of the configuration file named{{ prefix }}{{ server_id }}.hostkey.in.conf. - SSL Certificates: Managed automatically by the Certbot component within the Nginx container, storing secrets in the
nginx_secretsvolume.
Permission Settings¶
File and directory permissions are set as follows to ensure proper operation and security:
/opt/gitea: Owned byroot:rootwith mode0755.{{ gitea_data_dir }}: Owned by{{ gitea_user }}:{{ gitea_user }}with mode0755./root/nginx: Owned byroot:rootwith mode0755./root/nginx/compose.yml: Owned byroot:rootwith mode0644./data/nginx/user_conf.d: Accessible by the Nginx container for reading configuration files.
Starting, Stopping, and Updating¶
The services are managed using Docker Compose commands executed from their respective configuration directories.
-
Starting Gitea: Execute the following command from the
/opt/giteadirectory: -
Starting Nginx Proxy: Execute the following command from the
/root/nginxdirectory: -
Ensuring Service Status: The Gitea container is configured with a restart policy of
always, ensuring it remains running. The Nginx container uses a restart policy ofunless-stopped. -
Updating: To update the application, the
docker-compose.ymlfile must be modified with the new image version, followed by re-running thedocker-compose up -dcommand. The Nginx configuration updates involve regenerating thecompose.ymlfile and restarting the service.