This documentation page provides a step-by-step guide on how to deploy the gitlab-org/gitlab-discussions
project in production. It covers the necessary prerequisites, the deployment process, and code examples to illustrate key steps.
Prerequisites
Before proceeding with the deployment, ensure that the following prerequisites are met:
- Access to a production environment that meets the necessary requirements for running the
gitlab-discussions
application. - Docker and Docker Compose installed and configured.
- Necessary authentication credentials for accessing the GitLab container registry.
Deployment Steps
Step 1: Clone the Repository
First, clone the repository from GitLab to your local machine or directly to your production server.
git clone https://gitlab.com/gitlab-org/gitlab-discussions.git
cd gitlab-discussions
Step 2: Configure Environment Variables
Create a .env
file in the root of the project to hold the necessary environment configurations. Below is an example of what this file might include:
APP_ENV=production
DATABASE_URL=postgres://user:password@db_host:db_port/db_name
REDIS_URL=redis://redis_host:redis_port
SECRET_KEY_BASE=<your_secure_secret_key>
Ensure that you replace placeholder values with actual values relevant to your environment.
Step 3: Build the Docker Image
Once the environment variables are configured, build the Docker image. The following command will build the image as specified in the Dockerfile
.
docker build -t gitlab-discussions:latest .
Step 4: Deploy the Application
Use Docker Compose to bring up the entire application infrastructure. This includes all dependent services defined in the docker-compose.yml
file.
docker-compose up -d
The -d
flag runs the containers in detached mode, allowing your terminal to remain available for other commands.
Step 5: Run Database Migrations
Ensure that the database schema is up to date by running the necessary migrations. This command will execute any pending database migrations:
docker-compose exec app rails db:migrate
Step 6: Precompile Assets
To optimize the performance of your application, precompile the assets:
docker-compose exec app rails assets:precompile
Step 7: Health Check
Perform a health check to confirm that the application is running as expected. This can be done by accessing the application through a web browser or using command-line tools such as curl
.
curl -I http://localhost:3000
This command should return a 200 OK
response if the application is running successfully.
Step 8: Monitor Logs
To check the logs for any potential issues during startup, use the following command to tail the logs in the production environment:
docker-compose logs -f
Step 9: Rollback (if necessary)
In case of any issues, you can rollback to the previous version of the application using Docker’s tag management. For example:
docker tag gitlab-discussions:previous_version gitlab-discussions:latest
Then take the application down and bring it back up.
docker-compose down
docker-compose up -d
Conclusion
The deployment process for the gitlab-org/gitlab-discussions
project in a production environment involves careful preparation and execution of several steps. Following the outlined steps will ensure a smooth deployment while minimizing downtime and errors.
Source: gitlab-org/gitlab-discussions documentation