This documentation provides a comprehensive step-by-step guide for deploying the GitLab Community Edition (CE) in a production environment.
Prerequisites
Ensure the following prerequisites are in place before proceeding with the deployment:
Infrastructure: A server or virtual machine with appropriate resources.
Dependencies: All necessary dependencies must be installed. Refer to the project’s Dockerfile for a complete list.
Database: A PostgreSQL database should be set up and accessible from the GitLab server.
Step-by-Step Deployment
Step 1: Clone the Repository
Begin by cloning the gitlab-ce
repository to your target server.
git clone https://gitlab.com/gitlab-org/gitlab-ce.git
cd gitlab-ce
Step 2: Configure GitLab
Create a configuration file by copying the example configuration.
cp config/gitlab.yml.example config/gitlab.yml
Edit the config/gitlab.yml
file to adjust settings such as the external URL, database connection details, and other environment settings.
Step 3: Set Up the Environment
Generate the secret token needed for GitLab:
bin/gitlab-rake secret
Add the generated secret to your gitlab.yml
or secrets.yml
.
Step 4: Install Dependencies
Run the following command to install all application dependencies:
bundle install --without development test
Step 5: Database Setup
Create and set up the database:
bin/rails db:create RAILS_ENV=production
bin/rails db:migrate RAILS_ENV=production
If you have existing data, you may want to run the following command to import:
bin/rails db:seed RAILS_ENV=production
Step 6: Precompile Assets
Precompile the application’s assets to improve performance:
bin/rails assets:precompile RAILS_ENV=production
Step 7: Start GitLab
You can start GitLab using the following command:
bin/rails server -e production
Alternatively, if using a process manager such as Puma or Sidekiq, make sure these services are properly configured to run in a production environment.
Step 8: Configure Reverse Proxy (Optional)
For production usage, configure a reverse proxy such as NGINX.
A basic NGINX configuration might look like this:
server {
listen 80;
server_name gitlab.example.com;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Ensure the NGINX configuration is tested and reloaded after making changes:
sudo nginx -t
sudo systemctl reload nginx
Step 9: Monitor and Maintain
Once GitLab is up and running, set up monitoring for the application and database to ensure performance is maintained. Tools like Prometheus and Grafana can be beneficial for this purpose.
Step 10: Backup and Upgrade Procedures
Establish a routine backup mechanism for both the GitLab application data and PostgreSQL database.
bin/gitlab-backup create
For updates, follow established protocols to pull the latest code from the repository and repeat the migration, asset precompilation, and restarting processes as necessary.
Conclusion
Following these steps ensures a robust production deployment of GitLab Community Edition, tailored for optimized performance and stability.
References
- GitLab Community Edition repository: gitlab-org/gitlab-ce