Deploy an App using the Command Line
Last updated
Last updated
In this section, we will see how you can deploy your own app on Pollination Cloud using the command line. As an example to demonstrate the process, we will write and deploy an app that draws a wind rose using the EPW data. At the end of this section, you will have deployed an app named wind-rose that appears under the Apps tab on your profile.
Since this section builds on it, it is necessary that you go through this section first. Make sure that before you start going through this section, you have an app folder named "wind-rose" with the following structure.
The requirements.txt
file inside the app folder contains a list of dependencies that your app needs to run. We will update the requirements.txt file to include the libraries we need to run the app. This list will mostly differ for each app based on the libraries we need to run the app. if you are unsure about the libraries you need in this file, go ahead and start writing your app. Once you have finished writing the app, make sure to come back and update the requirements.txt file to reflect all the necessary libraries.
In the requirements.txt file, we will make sure to have the latest version of the libraries we need to run the app. Let's make the content of the file as follows;
These are the libraries we need to run the app. To find the latest version of any library that you may want to use with your app, please search for that library on the pypi website.
Change directory and arrive at the app folder created inside the wind-rose folder. Once app folder is your current working directory, run the following command. This will install all the dependencies in the requirements.txt file.
Now that we have the folder in place. We can write the app. We will be using the app.py file created in the app folder to write the app. Let's clear the file and write the following to generate a wind rose using the EPW data.
Please note that we created a subfolder called assets inside the app folder. This subfolder contains the EPW data file we are using renamed as sample.epw. So after creating the assets folder, the structure of the wind-rose folder will look like the following;
Once done, run the following command from inside the app folder;
This should render the following in the browser;
If the app runs as expected, enter ctrl + c
on the command line to stop the app.
Before, deploying the app, it is necessary to run the app in a Docker container. In order to run the app in a Docker container, we will need to install Docker desktop first. Visit this link to download the Docker desktop and install it on your system. Once installed, run the docker desktop and keep it running in the background.
Once the docker desktop is running, Let's go to the app folder and use the run
command from the Pollination-apps library to run the app in a Docker container.
You can find out the structure of this command by using the following command;
This should show the following in the command line;
Let's run the command now to run the app in a Docker container. The . here means that we want the current working directory to be the path.
This will take a while depending on the size of the app and the number of dependencies in the requirements.txt file. If everything works fine you should see the following appear in the command line;
Now, you can view the app in your browser by going to the following URL;
You should see your app running in the browser. If the app works as expected. Come back to the command line and use the ctrl + c
command to stop the app.
Once we have tested that the app works inside the Docker container. We are ready to deploy it to Pollination Cloud. To deploy the app, we will login to Pollination cloud first and will create an API token. Go to the Developer Settings section of the Settings page on your profile and create a new API or retrieve an existing API token. Here, we created a new API token with the name of wind-rose
. We will click on the refresh
button to get the API token and will copy the API token to the clipboard.
Warning Treat this API token as confidential. Make sure you don't commit it as part of your app to a public repository or share with others.
To deploy the app we will use the deploy
command from the Pollination-apps library.
In order to learn the structure of the command above, use the following command;
Finally, run the command inside the app folder and use the API token created in the step above.
Once you deploy the app, you should see the following message appear on the command line;
If you reached here, congratulations! You have successfully deployed the app to Pollination Cloud. Go to the wind-rose app under the Apps tab on your profile and check the live app after 10 minutes of deployment. You should see the wind-rose app live on Pollination cloud.
In the next section, we will see how we can use the CI generated by the github-manual
option to deploy this same app to Pollination.