High Quality Work!

Self-Motivation!

Despite the chaos:

Revised Project Proposals

Feedback this week!

Bonus

Hands-on Day! (C++ Functions and Classes)

// part 3
class SingletonConverter
{
   public:
       static SingletonConverter* getInstance( ) {
       
       	    static SingletonConverter* instance;
            return instance;
       
       };
       ~SingletonConverter( );
        float fromFtoC(float temp) {
            return ((temp-32)/1.8);
        };
   private:
       SingletonConverter( );
};
  //... in main
  SingletonConverter *c = SingletonConverter::getInstance()
  float convertedTemp = c->fromFtC(temp);
  //...

Lazy Loading!

But does it work?

#include <iostream>

//
// Singleton Converter w/ Lazy Loading
//
class SingletonConverter
{
   public:
       static SingletonConverter* getInstance( ) {
            static SingletonConverter* instance;
            return instance;
       };
       ~SingletonConverter( );
        float fromFtoC(float temp) {
            return ((temp-32)/1.8);
        };
        
   private:
       SingletonConverter( );
};

int main()
{

    SingletonConverter* i1 = SingletonConverter::getInstance();
    SingletonConverter* i2 = SingletonConverter::getInstance();
    SingletonConverter* i3 = SingletonConverter::getInstance();
    
    if (i1 == i2) {
        std::cout << "yes";
    }
    
    if (i1 == i3) {
        std::cout << "yes";
    }

}

Pointer arithmetic!

int carton[10];
int carton[10] = { };
int carton[10] = { 1, 3, 7 };

Array

#include <vector>

// ...

std::vector<float> allTemps;

std::cout << allTemps.size();

while(1) {

	std::string temp;
	std::cout << "Please enter a temperature or x to stop.";
	std::cin >> temp;

	if (temp == "x") {
		break;
	}

	allTemps.push_back( std::stof(temp) );

}

Vector

Dynamic containers..

Templates!

Developer

IT Operations

Software Developer

SysAdmins / IT Ops

should know a little bit of both!

Deployment

Delivery to Client or Customer

Make Software Accessible

Containers

Virtual Machines

Docker

All other platforms..

$ docker run --detach httpd
$ docker ps
$ docker inspect ID
$ docker pause ID
$ docker unpause ID
$ docker kill ID
$ docker run -it python:2.7

We can never know it all.

But we can be curious.

alias docker=podman

MicroVMs for AWS

No daemon required

# A basic apache server. To use either add or bind mount content under /var/www
FROM ubuntu:12.04

MAINTAINER Kimbro Staken version: 0.1

RUN apt-get update && apt-get install -y apache2 && apt-get clean && rm -rf /var/lib/apt/lists/*

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2

EXPOSE 80

CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]

Dockerfile

Base Docker

Author and version

Install Commands

Environment Variables

Open Ports

Executable Commands

This command can be overwritten when starting the container!

ENTRYPOINT ["/bin/bash"]

Fixed Command!

We will now create our own

Dockerfile

to specify a container

that downloads C++ code from Github,

compiles it,

and then runs it!

We will deploy the container using

This time just watch!

We will do it later together..

1. Create                   repository and clone it.

2. Add C++ code.

3. Create                  Dockerfile.

4. Build and tag Docker container.

5. Push container to                        !

6. Modify C++ code.

7. And see what happens...

#include <iostream>
#include <vector>


class SingletonConverter
{
   public:
       static SingletonConverter* getInstance( ) {
            static SingletonConverter* instance;
            return instance;
       
       };
       ~SingletonConverter( );
        float fromFtoC(float temp) {
            return ((temp-32)/1.8);
        };
   private:
       SingletonConverter( );
       
};

int main()
{

  std::vector<float> allTemps;

  while(1) {

      std::string temp;
      std::cout << "Please enter a temperature or x to stop entering temperatures.\n";
      std::cin >> temp;
      
      if (temp == "x") {
          break;
      }
      
      std::cout << "Stored " << temp << "!\n";

      allTemps.push_back(std::stof(temp));
      
  }

  std::cout << allTemps.size() << " temperatures stored!\n";

  float averageTemp = 0;
  for (int i=0; i<allTemps.size(); i++) {
    averageTemp += allTemps[i];
  }

  averageTemp /= allTemps.size();

  std::cout << "The average temperature is: " << averageTemp << "\n";

  std::cout << "Converted to Celsius, this temperature is " << SingletonConverter::getInstance()->fromFtoC(averageTemp) << "!\n";
  
}

converter.cc

FROM ubuntu:18.04

MAINTAINER Daniel Haehn version: 0.1


ADD converter.cc converter.cc

RUN apt-get update
RUN apt-get install -y g++
RUN g++ -o converter converter.cc

ENTRYPOINT ["./converter"]

Dockerfile

Docker commands we used today:

# build the container from the Dockerfile
docker build -t TAG .

# run the container interactively
docker run -it TAG

# login to DockerHub
docker login

# deploy the container
docker push TAG:latest

Container Orchestration

Run many containers on a cluster

Scalability

Docker Swarm

Kubernetes

easy

complex

CS410 Lecture 21

By Daniel Haehn

CS410 Lecture 21

Slides for CS410 Software Engineering at UMass Boston. See https://cs410.net!

  • 29

More from Daniel Haehn