This guide will walk you through creating a Docker environment using Earthly and DevContainer. We'll begin by setting up a Docker file to utilize Ubuntu's snapshot repositories, then explore how to build images for different architectures. Finally, we'll integrate Earthly for streamlined builds and testing, and set up a development container for a complete development environment.
Utilizing Ubuntu Snapshot Repositories
Open your Daytona workspace.
Create a Docker file to access Ubuntu snapshot repositories, which allow you to use a specific snapshot of Ubuntu packages from a certain date.
Define the snapshot date in the
config.toml
file. For example, set it to November 5, 2023.In your Docker file, instruct it to fetch packages from the Ubuntu snapshot as of the specified date and update the sources list accordingly.
Building for Multiple Architectures
To support both x86 and ARM architectures, use Docker's buildx feature.
Execute the Docker buildx command, specifying platforms for AMD and ARM.
Incorporate variables into the build process to manage different configurations.
Simplifying with Earthly
Instead of separate Docker and make files, combine your configuration into one Earthly file.
Set global variables for the build date and snapshot in the Earthly file.
Use the Earthly file to build your Docker target and add a simple smoke test to verify package installation.
Setting Up DevContainer
Start with an Ubuntu Jammy base for your DevContainer.
Configure environment variables to pass GitHub credentials and set up Docker and Earthly.
Ensure the DevContainer includes necessary extensions for make, Docker, and Earthly.
Automate login to GitHub registry upon starting the DevContainer.
Testing and Building with Earthly
Verify Earthly installation by running a test command.
Observe Earthly's build process, which includes pulling the base image and updating package lists.
Push the completed build to your repositories using the Earthly push command.
Advantages of Using Earthly
Earthly caches your builds, making subsequent builds faster.
A single Earthly file simplifies the build and test process.
Integration with DevContainer provides a ready-to-use development environment with all necessary tools installed.
Code and Full Tutorial on YouTube
For those interested in exploring the code and configurations discussed in this guide, the Git repository is available at https://github.com/metcalfc/snapshot-base. Additionally, to see these steps in action, you can view the full video tutorial on YouTube, which provides a comprehensive walkthrough of the entire process.
Conclusion
By following these steps, you can set up a Docker environment that leverages the power of Earthly and DevContainer. This setup allows for efficient management of Docker builds, streamlined testing, and a fully equipped development container, ensuring a smooth and productive workflow.