By kicaj
I would like prepare my old project to work wiith separate environments, e.g. for Development, Staging and Productions. I would like hear about your experience or listen your suggestion.
Project is hosted on Github and CI/CD will be running by Github Actions.
I would like prepare 3 stages:
debug = true, with API keys for sandboxes, database migrations, database seeds and unit, integration and e2e tests;debug = false, with API keys for sandboxes, database seeds and unit, integration and e2e tests;debug = false, with target API keys and database migrations.I prepare sepearate workflows on Github: staging.yaml and production.yaml.
Of course, it’s not necessary for works on development stage.
Also I use Deployer for running commands, but it’s not that relevant for this thread.
staging.yaml:
step: build
- build docker environment (or pull and push)
- run docker
- build app (e.g. install vendors)
- unit tests
- integration tests
- export build app as artifacts
step: prepare server (e.g. droplet on DigitalOcean)
- unzpi artifacts
- build docker enviroment with e.g. database
- run docker
- install vendors
- database seeds
step: tests
- run e2e tests
step: publish
- set subdomain (or domain) to docker environment
production.yaml:
step: build
- build docker environment (or pull and push)
- run docker
- build app
- export build app as artifacts
step: connect to existing server (e.g. droplet on DigitalOcean)
- make new dir in releases/ directory
- unzpi artifacts to newest directory in releases/ directory
- run docker (or no)
- database migrations
- symlink direcotry (used as DOCUMENT_ROOT) do newest directory in releases/ directory
step: publish
- just set success message
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi there,
This is indeed an interesting and broad topic! Overall, your plan for implementing a CI/CD pipeline with separate environments for development, staging, and production is well-designed.
Here are some specific comments and recommendations:
Stages and Environments
Staging and Production Workflows
It is generally a good practice to keep staging and production workflows separate. This allows you to deploy to staging without necessarily deploying to production immediately. However, automating the pipeline such that production deployment is dependent on staging passing all checks is also a good approach, especially for more mature applications where staging is merely a sanity check before production.
One thing to consider is that while running tests on staging is essential, running a full suite of unit tests may be overkill, especially if they have already been run during the development phase and again in the CI pipeline.
Docker Image Building and Reusability
To speed up the CI/CD process and avoid duplicating efforts, build your Docker image once, push it to a Docker registry (e.g., Docker Hub, GitHub Packages, or any other Docker registry), and then pull the same image in subsequent steps or jobs. This way, you avoid rebuilding the application multiple times.
A word of caution: Ensure that sensitive information (like API keys) is not baked into the Docker image. Instead, use environment variables to inject them when running the container.
Artifacts
Database Migrations and Seeds
Rollbacks
Notifications
Best,
Bobby
Heya,
I like your plan for setting up separate environments for your project using GitHub Actions and Docker. It seems solid, but here are a few suggestions and considerations:
Here are some answers to your specific questions:
Here are some additional considerations:
Overall, your approach seems reasonable, but there are ways to optimize and streamline the process to reduce duplication and improve efficiency in your CI/CD pipeline. It’s important to strike a balance between automation and flexibility to meet your project’s specific needs.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.