Deploying Zombie Frontend - cogeorg/teaching GitHub Wiki

In this part, we will publish the docker image we created in the previous step, pull it to a remote server and run it there....

Publishing the Docker image to Github

In the previous step, we built a Docker image called zombie-frontend:0.1.0, where zombie-frontend is the name and 0.1.0 is the version of that image.

Github allows you to publish that image in their registry. If you look at your repository on github.com, you will see a tab called packages:

img

The very first thing you need to do is create an access token. Github provides a tutorial that walks you through the steps. Please enable the scopes write:packages, read:packages, and delete:packages.

Now, let's set publish the image to Github packages. First authenticate:

$ docker login docker.pkg.github.com --username YOUR-USERNAME -p YOUR-ACCESS-TOKEN

Next, we need to tag the docker image we created. Therefore, we need to find out the image ID. You can do that by typing

$ docker images

which will return something like

img

Here, the image ID is bdca521ead6e. Now, we can tag the docker image:

$ docker tag IMAGE_ID docker.pkg.github.com/YOUR-USERNAME/YOUR-REPOSITORY-NAME/zombie-frontend:0.1.0

Finally, we push the image to Github packages:

$ docker push docker.pkg.github.com/YOUR-USERNAME/YOUR-REPOSITORY-NAME/zombie-frontend:0.1.0 

Creating a remote virtual server

Google is quite generous and gives everybody $200 worth of credits on their cloud computing platform. Hence, we can create an Ubuntu instance at their platform. There is already a fantastic guide that walks you through all the necessary steps.

Generating an SSH key

If you are not sure whether you already have an SSH key, test it by running the following in your terminal:

$ ls -al ~/.ssh

If nothing is shown, generate a new SSH key pair by typing:

$ ssh-keygen -t rsa

It is convenient to leave the password blank. Now, you can display the newly created key by running:

$ cat ~/.ssh id_rsa.pub

Add the key to your Ubuntu instance when asked to.

Pulling your docker image onto the server

Once you have created your Ubuntu instance on Google cloud, you should also have set up a static IP address.

Log into your server by running

$ ssh USERNAME@STATIC-IP

Docker is not automatically installed so the first thing we need to do is to install it here as well. Please refer to the installation guide for Ubuntu in the Docker section.

Once docker is installed, log into your docker registry, pull the docker image, and run it:

$ docker login docker.pkg.github.com --username YOUR-USERNAME -p YOUR-ACCESS-TOKEN
$ docker pull docker.pkg.github.com/YOUR-USERNAME/YOUR-REPOSITORY-NAME/zombie-frontend:0.1.0 
$ docker run -d --name zombies -p 3000:3000 -p 3001:3001 docker.pkg.github.com/YOUR-USERNAME/YOUR-REPOSITORY-NAME/zombie-frontend:0.1.0

You should now be able to access your frontend at http://STATIC-IP:3000. Congratulations, you have deployed your frontend!

You exit the server by just typing

$ exit