Deployment using docker


Before initiating the deployment process, it is beneficial to understand the purpose and functionality of both Drone and Docker Compose.

Drone and Docker Compose play important roles in the CI/CD (Continuous Integration/Continuous Deployment) process.

Drone is a popular CI/CD platform that helps automate the build, test, and deployment of applications. It integrates with version control systems, allowing developers to define pipelines and workflows to build, test, and deploy their code automatically. Drone facilitates the orchestration of these CI/CD processes and provides features like parallel testing, artifact management, and deployment to various environments.

Docker Compose, on the other hand, is a tool that simplifies the deployment of multi-container applications. It allows you to define and manage your application's services, dependencies, and network configurations using a declarative YAML file. Docker Compose enables the creation of isolated and reproducible environments, making it easier to develop and deploy applications consistently across different environments.

Drupal App

Env file

  1. Copy .env to your env file (example .env.staging).

  2. Fill the Environment variables with the accurate values.

Docker compose file

  1. Copy docker-compose.prod.yml to your docker compose file (example docker-compose.staging.yml)

  2. Update the value of the env_file property within the services section of your Docker Compose file with the correct filename of your environment file.

env_file: .env.staging

Drone file

  1. Copy .drone.yml to your drone file (example .drone.staging.yml).

  2. Update the values of the --project-name, --env-file properties, and the docker-compose.yml file according to your specific requirements.

Change this :

docker-compose --project-name vactory_drupal -f docker-compose.prod.yml --env-file=.env.prod build

To :

docker-compose --project-name my_project_drupal -f docker-compose.staging.yml --env-file=.env.staging build
⚠️
Verify that you have replaced all occurrences of the `--project-name`, `--env-file` properties, and the `docker-compose.yml` file within the drone configuration.

Change this :

docker exec vactory_php drush cr

To :

docker exec PROJECT_NAME_php drush cr
⚠️
Replace the `PROJECT_NAME` placeholder with the actual value mentioned in your .env file.
  1. Save changes.

Visit your Drone CI instance.

First, find the repository using the search bar, On the settings page :

Modify the configuration input by specifying your .drone file.

Next, add secrets(sensitive information required for build steps such as DB env vars, memcached vars, pma vars ...)

⚠️
Locate all the necessary secrets in the .drone file and create them within the drone instance, ensuring that you assign the appropriate values to each secret.

Now commit your changes, and push to the repository, it will trigger a new build on Drone CI.

Although the build has passed successfully, the code has not been updated on the server yet. One more crucial step is required, which involves promoting the build.

NextJs App

Dockerfile

  1. Copy .Dockerfile.staging to your Dockerfile file.

  2. Replaced all occurrences of starter by your project name.

Docker compose file

  1. Copy docker-compose.yml to your docker compose file.

  2. Replaced all occurrences of vactory (on containers name, traefik rules name) by your project name.

  3. Make sure you changed the Host on treafik rules by your host.

Nginx Default Config

Edit the nginx default.conf file :

./.docker/nginx/default.conf

upstream node_app_backend {
server frontend_container_name:port;
keepalive 32;
# keepalive_requests 200;
}

Replace :

  • frontend_container_name: Your front end container name.
  • port: The port specified in the Dockerfile for your frontend application, which is exposed for external access.

Drone file

  1. Copy .drone.yml to your drone file.

  2. Update the values of the env variables, --project-name, and the docker-compose.yml file according to your specific requirements.

  3. Save changes.

Visit your Drone CI instance.

First, find the repository using the search bar, On the settings page :

Modify the configuration input by specifying your .drone file.

Next, add secrets(sensitive information required for build steps such as DB env vars, memcached vars, pma vars ...)

⚠️
Locate all the necessary secrets in the .drone file and create them within the drone instance, ensuring that you assign the appropriate values to each secret.

Now commit your changes, and push to the repository, it will trigger a new build on Drone CI.

Although the build has passed successfully, the code has not been updated on the server yet. One more crucial step is required, which involves promoting the build.