Recently we learned that as of September 30th, 2023 several linux images will be deprecated, including the one we used, ubuntu-2004:202111-02. Therefore, after September 30th, our pipelines would have failed. To avoid this, we switched several machines in our Django project from Ubuntu GPU images to convenience images; This writing details that switch.
Updating a GPU machine image can be a bit tricky. One must ensure that the base image language version and project language version match. Otherwise, updating the GPU image version might result in inadvertently updating the base language version. Resulting, for instance, in a project that uses Python 3.9 and an image (in case of a test image) running those tests in Python 3.11. This might result in issues.
To avoid having to constantly update our image, to ensure that our image version is what we intend it to be, and to embrace CircleCI’s current technology we migrated to a next-generation convenience image. According to CircleCI, convenience images are “extensions of official Docker images, and include tools especially useful for CI/CD.” The next-generation convenience images were “built from the ground up with CI, efficiency, and determinism in mind.” CircleCI claims that the next-generation images have a faster spin-up time and have improved reliability and stability.
Here’s what part of our old test machine configuration was like:
test: machine: image: ubuntu-2004:202111-02 environment: DATABASE_URL: postgres://postgres@localhost:5432/ronard_db PGHOST: localhost PGPORT: 5432 PGUSER: ron_user working_directory: ~/ronard_project steps: - checkout - restore_cache_cmd - run: name: Create venv command: | python3 -m venv env
On the soon-to-be deprecated Ubuntu machine, we had a Postgres database to run our tests (Postgres started in the steps section). Then we checked out the branch, restored the cache, created a virtual environment, etc.
test: docker: - image: cimg/python:3.9 environment: DATABASE_URL: postgres://postgres@localhost:5432/ronard_db PGHOST: localhost PGPORT: 5432 PGUSER: ron_user - image: cimg/postgres:12.14 environment: POSTGRES_USER: ron_user POSTGRES_DB: ronard_db working_directory: ~/ronard_project steps: - checkout - restore_cache_cmd - run: name: Create venv command: | python3 -m venv env
- Several things needed to change for the convenience image - key points to note:
- Replacing the word machine to docker below the image name.
- Replacing the old Ubuntu image with a convenience image cimg/python:3.9 (convenience image python 3.9).
- Specifying the environment variables that belong to each image below it
- Specifying a Postgres image with matching credentials to the Python image.
- The rest of the configuration file remains pretty much the same.
- Further considerations:
- While not necessary, it is a good idea to update/clear the cache key variable on your configuration file.
- If you had a step to bring up the database or to start docker, remove it since you now will use a docker image and you will be inside of such container.
By embracing the power of convenience images, you're ensuring that your projects are well-equipped for the challenges and opportunities that lie ahead. Happy coding and happy building!