ECE366 - Lesson 10

Hosting on the Cloud, Testing

Instructor: Professor Hong

Review & Questions

## Your First Azure Container
## Installing CLI - [https://learn.microsoft.com/en-us/cli/azure/install-azure-cli](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli) - Azure Login: - WSL: ```az login --use-device-code``` - Mac: ```az login```
## Your First Container - [https://learn.microsoft.com/en-us/azure/container-instances/container-instances-quickstart](https://learn.microsoft.com/en-us/azure/container-instances/container-instances-quickstart) ``` $ az group create --name myResourceGroup --location eastus $ az container create --resource-group myResourceGroup --name mycontainer --image mcr.microsoft.com/azuredocs/aci-helloworld --dns-name-label aci-demo --ports 80 $ az container show --resource-group myResourceGroup --name mycontainer --query "{FQDN:ipAddress.fqdn,ProvisioningState:provisioningState}" --out table ``` - Run the site provided - You will have to update your dns label name
## Azure With Docker Compose
## Sample [https://learn.microsoft.com/en-us/azure/container-instances/tutorial-docker-compose](https://learn.microsoft.com/en-us/azure/container-instances/tutorial-docker-compose) ```$ az acr repository show --name --repository azure-vote-front``` - remove the initial directory in the above command - wait a few minutes after pushing before the IP address works
## React and Docker
## Adding React to Docker Compose Dockerfile ``` # pull official base image FROM node:18 # set working directory WORKDIR /app # add `/app/node_modules/.bin` to $PATH ENV PATH /app/node_modules/.bin:$PATH # install app dependencies COPY package.json ./ COPY package-lock.json ./ RUN npm install --silent RUN npm install react-scripts@3.4.1 -g --silent # add app COPY . ./ # start app CMD ["npm", "start"] ```
## Update Proxy package.json ``` "proxy": "http://app:8080/", ```
## Initializing DB In Docker Compose Dockerfile ``` FROM postgres # Copy the SQL files to the container COPY init.sql /docker-entrypoint-initdb.d/0_init.sql COPY users.sql /docker-entrypoint-initdb.d/1_users.sql COPY game.sql /docker-entrypoint-initdb.d/2_game.sql ```
## Docker-Compose docker-compose.yaml ``` services: db: image: postgres build: context: db environment: - POSTGRES_DB=postgres - POSTGRES_PASSWORD=password expose: - 5432:5432 ports: - 5432:5432 restart: always app: build: server/rps expose: - 8080:8080 ports: - 8080:8080 environment: - POSTGRES_DB=postgres - POSTGRES_PASSWORD=password depends_on: - db ui: build: client ports: - 3000:3000 depends_on: - app ```
## Docker Compose Push
## Updated docker-compose.yaml ``` services: db: image: cooperps.azurecr.io/db build: db container_name: db environment: - POSTGRES_DB=postgres - POSTGRES_PASSWORD=password expose: - 5432:5432 ports: - 5432:5432 restart: always app: build: server/rps image: cooperps.azurecr.io/app container_name: app expose: - 8080:8080 ports: - 8080:8080 environment: - POSTGRES_DB=postgres - POSTGRES_PASSWORD=password depends_on: - db ui: build: client image: cooperps.azurecr.io/ui container_name: ui ports: - 3000:3000 depends_on: - app ```
## Pushing to Azure ``` az group create --name cooperps --location eastus az acr create --resource-group cooperps --name cooperps --sku Basic az acr login --name cooperps # update docker-compose docker-compose up --build -d docker ps # test locally docker-compose down docker-compose push az acr repository show --name cooperps --repository ui docker login azure docker context create aci cooperps docker context use cooperps docker compose up ``` - Should be able to go to the IP address to view the site
## Back to normal docker ``` docker context use default ```
## Testing in Java
## Testing Resources [https://medium.com/capital-one-tech/improve-java-code-with-unit-tests-and-jacoco-b342643736ed](https://medium.com/capital-one-tech/improve-java-code-with-unit-tests-and-jacoco-b342643736ed) [https://www.jetbrains.com/help/idea/running-test-with-coverage.html#run-config-with-coverage](https://www.jetbrains.com/help/idea/running-test-with-coverage.html#run-config-with-coverage)
## Project Check-in - Please send me your available times over the next week - 30 minute check-in for project