⏲️ Est. time to complete: 60 min. ⏲️
Today you will learn how to:
First, let’s get started with the frontend application - The part that you will see and use on your mobile phone or your web browser. This is the main way to interact with Milligram’s services.
We’ve prepared an automated way to create and update the website for you. You will use two of GitHub’s awesome features. GitHub Pages and GitHub Actions. Let’s get started with the actions.
A repository contains all of your project’s files and each file’s revision history. You can discuss and manage your project’s work within the repository.
Make sure that the Actions have read/write permissions. Check this via Settings->Actions->General and scroll down to the Workflow permissions section. Click the Read and write permissions option. Click Save.
Now, observe how the workflow is being run and take a look at the individual steps that are run for you by GitHub.
To be able to display the website (frontend) we’ve built and deployed using GitHub Actions, we need to enable GitHub Pages for your repository. GitHub Pages are an easy way to display a static website related to your repository. Many people use it to display the documentation for their projects. We will use it to serve the frontend for Milligram.
https://<your github username>.github.io/anyonecancode/
.Take a look at the website. Try changing the profile to your GitHub account name and see that it is stored even if you refresh the browser.
Milligram is a fun little app similar to photo based social media that you might be familiar with. Of course we want to use it on our mobile phones so we can use the cameras to take awesome selfies and pictures for Milligram. Its main features are:
To make the first modifications, open your personal Milligram website on your phone and explore it’s content. Then edit the profile in the app to show your own GitHub profile picture in the app.
On modern mobile phones, you can “install” web apps on you homescreen to make them more accessible and make them look more like an app from an official appstore. Therefore, we will not add the app to our phones’ homescreen.
The application backend will receive uploaded photos, store them for us and return them when needed.
Our application can be divided into a frontend (something you see and runs locally on your phone) and a backend (something which processes your information). In this case, as we want to create our own social media application, we need pictures to be stored for our “News Feed”. That means we need a place to store many files and a place to run our application logic (which is our programming code).
To store the files, we will use an “Azure Storage Account” and to run our application, we will use an “Azure Web App”. First things first - sign into your “Azure Account”.
Go to your browser and visit portal.azure.com.
Log in with your Azure Account
. The login information is provided to you by your trainer. Ask them if you don’t know where to find it.
Our storage account is the place where we “save” our pictures for our news feed. Inside the storage account we use the so called Azure Blob Storage. The Blob Storage can hold a massive amount of files. Just like the disk or storage on your computer. A cool fun fact is that you can store as many photos on the storage account as you like and you don’t have to worry about your storage space.
Azure Resource: In Azure, the term resource refers to an entity managed by Azure. For example, virtual machines, virtual networks, and storage accounts are all referred to as Azure resources.
Azure Resource Group: A resource group is a container that holds related resources for an Azure solution. The resource group can include all the resources > for the solution, or only those resources that you want to manage as a group.
Standard
for Performance and Locally-redundant storage (LRS)
for Redundancy.
images
. Leave everything in the preconfigured settings as is.This is the place where all uploaded images to our Milligram app will be stored.
Our Azure Web App is a computer managed by Microsoft where you can easily run your own application without worrying about software updates, security issues, backUp or hardware issues (as you might have already experienced on your phone).
<pick your own unique name>
Code
Python 3.8
Linux
West Europe
<pick your own name>
.
:::tip 📝 On the review page, you can find information about the estimated costs of your service. Make sure it displays Estimated price - Free :::
Now let’s connect our application with our storage so that you can take pictures on your phone and store them. We need to tell the Web application where it can find our storage service. The application can take external configurations to configure the connection to the storage account.
STORAGE
<paste your (earlier copied) connection string from Storage Account>
Custom
ok
and Save
.https://<YourGithubHandle>.github.io
under Allowed Origins.Save
again.Now your storage account and web app are successfully connected and can communicate with each other.
There is still a small configuration missing. Our app uses a ready-made module so that users can interact with their content. But this module is not installed yet. In order for it to be installed, we provide the web app with a configuration that is executed when the app is launched, allowing users to interact with our app’s data.
gunicorn -k uvicorn.workers.UvicornWorker
and hit Save.
To ensure our social media application can actually do something, we need to bring our source code to the Azure Web App. To do that we will automate this so called “deployment”. Hence, we don’t have to rely on a manual process every time we want to make changes (e.g. changing the title of the application) to our application and thus, we avoid many mistakes.
anyonecancode
as well as the main
Branch.Save
.Once you have hit Save
the service automatically creates a workflow file in your GitHub repository. This workflow is immediately being executed and after about 2 minutes your web app is ready. You can also check your deployment on your “Actions” tab in your repository. The color green is always a good sign.
Let’s pause a second. To make sure that you are on track, test if our app’s frontend gets a response from our backend service. Before we bring everything together, we want to make sure the backend service is working as expected.
In your browser you will have the following view:
:::tip 📝 If you want to learn more about Swagger have a look at Wikipedia. :::
Select the GET/images endpoint, hit Try it Out
and then hit Execute
. Once you get the 200 Response code, you have a successful running service. Congratulations!
:::tip 📝 Look at the HTTP Response Codes at Wikipedia. 2xx Codes generally mean success, where as 4xx and 5xx Codes show different kinds of errors. You probably know 404 - Not Found. :::
Now that we are sure that our backend service works as expected, we can bring everything together.
To do this, we will use a GitHub feature called Secrets, where you can store your backend URL to make your frontend talk to the backend service.
VITE_IMAGE_API_URL
and as value set <your WebApp's URL>
.
⚠️⚠️ Your URL should end on a /. It should look like this:
https://xxxx.azurewebsites.net/
For the change of adding the secret taking effect in the frontend, we need to run our build pipeline again so that the process can pickup the newly created setting.
Navigate to the Actions tab, select the pages workflow and rerun the workflow:
Click on the frontend link displayed under the deploy step under your pipeline https://<yourGithubHandle>.github.io/...
or reopen the App on your phone.
Our frontend application should now have a new button with a camera symbol that allows us to take pictures. These pictures should then appear on the timeline or news feed.
So go ahead and take at least 5 pictures and make sure they appear in your app. Make sure to share them with at least 1-2 friends so they can also upload their photos to your News Feed.
That’s a wrap for today. Congrats!
Tomorrow, we will make our app smart by adding artificial intelligence to it for detecting objects within your images as well as talking to our app.
Ask your coach if you did not succeed. We have you covered with a back up.
Look at the prepared application with our pictures for you to play around Milligram.
◀ Previous challenge | 🔼 Home | Next challenge ▶ |