Graduating a data container allows you to create a data image from it. This is useful when you make changes to a data container and want to use its current state as the baseline for future work. A good example of when to use the
graduate command would be when you were able to reproduce a bug and want to share the state of your database with others. You can graduate the data container and share the resulting data image with your team.
In this tutorial we will create a data image, then create a data container from that image. We will then make some changes to the database, save them and perform a graduation. This will create a new data image. We will use this image to create a new data container and inspect its current state.
As a prerequisite you should've followed the instructions to install spawnctl
Create a file
development.yamlwith your data image specifications.sourceType: emptyname: devengine: postgresqlversion: 11.0
In this case we want to create a PostgreSQL data image that is completely empty and is named
Run the following command to create a data image.$ spawnctl create data-image -f ./development.yamlData image 'dev' (10001) created!
You can verify your data image by running the following command.$ spawnctl get data-imagesNAME IMAGE ID ENGINE STATUS MESSAGE CREATEDdev 10001 PostgreSQL 2 Created 2 minutes ago
Create a data container from the newly created data image.$ spawnctl create data-container --image devData container 'dev-rambbomj' (10001) created!-> Host=instances.spawn.cc;Port=53223;User ID=<some_user_id>;Password=<some_password>;
You can verify your data container was properly created by running the following command.
Notice the created data container has revision
rev.0.$ spawnctl get data-containersNAME CONTAINER ID REVISION STATUS MESSAGE ENGINE CREATEDdev-rambbomj 10001 rev.0 2 Running PostgreSQL 1 minute ago
You should now be able to connect to your database and execute queries.
In this example we connect to the PostgreSQL data container (database) using psql.$ psql -h instances.spawn.cc -p 53223 -U <some_user_id>Password for user <some_user_id>:psql (10.5, server 11.0 (Debian 11.0-1.pgdg90+2))SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)Type "help" for help.<some_user_id>=# CREATE TABLE customers(id INT);CREATE TABLE<some_user_id>=# \dtList of relationsSchema | Name | Type | Owner--------+-----------+-------+------------------public | customers | table | <some_user_id>(1 row)
We can now perform a save operation on this data container.$ spawnctl save data-container dev-rambbomjSaving container....Data container 'dev-rambbomj' saved!New revision is 'rev.1'
We can now perform a
graduateoperation on this data container.
Now that our new changes are saved, we want to make the current state of this data container (database) the baseline for future work.$ spawnctl graduate data-container dev-rambbomj --revision rev.1Successfully graduated data container 'dev-rambbomj' at revision 'rev.1' to a new data-imageNew image 'dev-rambbomj-graduate-1' (10002) available!
You can verify the new data image by running the following command.$ spawnctl get data-imagesNAME IMAGE ID ENGINE STATUS MESSAGE CREATEDdev 10001 PostgreSQL 2 Created 2 hours agodev-rambbomj-graduate-1 10002 PostgreSQL 2 Created 2 minutes ago
Notice the name of the new image is
dev-rambbomj-graduate-1. This is because it was created from the graduation of a data container.
You can now create a data container from that image.$ spawnctl create data-container --image dev-rambbomj-graduate-1Creating data container......Data container 'dev-rambbomj-graduate-1-hztarabe' created!-> Host=instances.spawn.cc;Port=53224;User ID=<some_user_id>;Password=<password>;
Connect to this data container and verify its content.$ psql -h instances.spawn.cc -p 53224 -U <some_user_id>psql (10.5, server 11.0 (Debian 11.0-1.pgdg90+2))SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)Type "help" for help.<some_user_id>=# \dtList of relationsSchema | Name | Type | Owner--------+-----------+-------+------------------public | customers | table | spawn_admin_jmij(1 row)
Notice that the table
customerswe created previously is present. This is because after creating the table, we saved the data container and then graduated. The graduation operation created a new image. All subsequent data containers based on this image will contain a copy of the data.