CI/CD Outline
This outline describes the CI/CD pipeline for the GitLab Discussions project. It covers how the code is built, tested, and deployed.
Pipeline Structure
The CI/CD pipeline is defined in .gitlab-ci.yml
file located at the root of the project. It uses the following stages:
- build: Builds the project code.
- test: Runs tests.
- deploy: Deploys the application to the target environment.
Building
The build
stage uses the docker
executor to build a Docker image for the application. The image is tagged with the current commit SHA.
build:
stage: build
image: docker:latest
script:
- docker build -t gitlab-org/gitlab-discussions:$CI_COMMIT_SHA .
Testing
The test
stage runs unit and integration tests using the rspec
framework. The tests are run against the built Docker image.
test:
stage: test
image: docker:latest
script:
- docker run -d -p 3000:3000 gitlab-org/gitlab-discussions:$CI_COMMIT_SHA
- sleep 10 # Wait for the server to start
- rspec
dependencies:
- build
Deployment
The deploy
stage is responsible for deploying the application to the target environment. This is done using the Kubernetes
executor.
deploy:
stage: deploy
image: kubernetes:latest
script:
- kubectl apply -f k8s/
only:
- master
Options
CI_COMMIT_SHA
: This variable contains the commit SHA of the current commit. It’s used to tag the Docker image.only: master
: This limits thedeploy
stage to only run when the code is pushed to themaster
branch.dependencies: build
: This ensures that thetest
stage runs only after thebuild
stage has completed successfully.
Examples
- Building and testing:
build: stage: build image: docker:latest script: - docker build -t gitlab-org/gitlab-discussions:$CI_COMMIT_SHA . test: stage: test image: docker:latest script: - docker run -d -p 3000:3000 gitlab-org/gitlab-discussions:$CI_COMMIT_SHA - sleep 10 # Wait for the server to start - rspec dependencies: - build
- Deploying to a specific environment:
deploy: stage: deploy image: kubernetes:latest script: - kubectl apply -f k8s/ only: - master environment: name: staging
References
.gitlab-ci.yml
: -/.gitlab-ci.yml