The deployment is done using docker images with the help of make tasks. We can create a docker image, push it to container registry on gcp and then launch an instance using this docker image
The docker image is automatically tagged with the application version from your mix file
Before you begin:
- Make sure you have write access to the docker registry
- You will need the necessary permissions to create an instance
- Docker should be installed in your computer and running
- GCloud should be well set up, authenticated and initialised to use docker
- access to production secrets in the
prod.secrets.exs
file (look atconfig/prod.sample.exs
to see an example)
If you want to create a docker image for use in your laptop then you can use the command
make docker-image
You can optionally create an image on your laptop and push it up to GCP container registry using the following command
make push-image-gcp
This will create the image and tag it with the current application version then push the created image to GCP
You can also run a server on GCP using the docker image by running the following command
make push-and-serve-gcp instance-name=<give-the-instance-a-unique-name>
If you had created an image before and would like to create a running server using the image run:
make deploy-existing-image instance-name=<give-the-instance-a-unique-name>
The instance name you provide above should be unique and should not be existing on GCP already otherwise you will get an error
If you want to update an already running instance with a different version of the application, you need
to ensure that the image is created and pushed to gcr.io using make push-image-gcp
after which you can update an instance to use the image.
This is done by specifying the tag to the image you want to use (image-tag
) and the running instance you want to update (instance-name
)
make update-instance instance-name=<existing-instance-name> image-tag=<existing-tag-on-gcr>
An example would be:
make update-instance instance-name=testinstance image-tag=0.5.0
The above procedures create an instance of this project on GCP with the name you gave it. Using console.cloud.google.compute, go to your virtual machine instances, and look up the external ip (a.b.c.d5) of the instance you just created (if you used one of the make commands then the ip address will be listed upon successful startup of the instance). Note the phoenix webserver is running on port 4000 Go to http://a.b.c.d:4000/ Note it is http not https
You can set the following custom environment variables when building the image or launching a vm instance
- CLIENT_ID
- MQTT_HOST
- MQTT_PORT
- USER_NAME
- PASSWORD
When running the make commands above you can add any of the variables above that you want to customise for example:
make deploy-existing-image instance-name=<a-unique-name> CLIENT_ID=<your_new_id> USER_NAME=<prefered_name>
If you want to update an already running instance with a different version of the application, you need
to ensure that the image is created and pushed to gcr.io using make push-image-gcp
after which you can update an instance to use the image.