Skip to main content

DevOps Topics

Overview

The purpose of this document is to specify different devops topics from building, testing and deploying to developing in a container with docker.

Visual Studio Code

VS Code will be used for all major development. For the most up to date IDE, it is encouraged that users develop on the cloud development machine. The Remote-Containers and Remote-SSH extensions must be installed. Any additional extensions will be automatically installed when setting up the remote environment

Setup

  • On the local machine with VS Code, you will need to generate a keypair for Gitea

    ssh-keygen -t ed25519 -C "your_email@example.com"

     

  • Be sure to add it to the agent with
    eval "$(ssh-agent -s)"

    ssh-add <path-to-ssh-key>

    Once your key has been added to Gitea, you can develop either on a remote machine or your local machine.

On same local machine
  • On the local machine with VS Code, generate another keypair to put on the remote machine
    ssh-keygen -t ed25519 -C "your_email@example.com"

     

  • On the local machine add the keypair to your ssh agent
    eval "$(ssh-agent -s)"

    ssh-add <path-to-ssh-key>

     

  • On the remote machine, you can put the public key in your ~/.authorized_keys file
  • Open the remote location in VS Code
  • You should be prompted in the bottom left corner to reopen the project in a container
On a remote machine
  • Make sure docker is installed and the docker plugin is installed in VS Code
  • Open the folder in VS Code
  • You should be prompted in the bottom left corner to reopen the project in a container

Starting a new project

To start a new project, you will need to make a template repository with the Hello World Microservice repository. This can easily be done with Gitea by adding kheestand/HelloWorldMicroservice as a template repository when creating the repository.

Once you have the HelloWorldMicroservice added as a base repository, you will need to modify the .env file located at /workspace/.openapi/.env. Your .env file should look something like this:

{
    "schemaLink" : "<link to openapi schema>"
}

Note: you will need a link to a valid openapi schema. You can use the pet store api if you just want to test these instructions.

Once your .env file is ready, you can select the Start new Project task in VS code by pressing Ctrl + Shift + P on your keyboard and selecting Tasks: Run Tasks and then Start New Project.

Updating the template repository

In VS code you can use the following commands to update the template

git fetch --all
git merge template/master

After running git fetch you might need to commit the changes to finish the merge. This can be done through VS Code's Source Control menu. You also might need to allow unrelated histories which you can do by modifying the git merge command to

git merge template/master --allow-unrelated-histories

Running the Code

Code can be ran by pressing the F5 key or by pressing the Run Code button in VS Code's debug menu

Running Tests

Unittest is used to run tests for the microservice. Tests can be found in the test menu in VS Code. If you need to create more tests, VS code will look in the server folder for a file with the regex named test_*.py. The default code is located in the path /workspace/server/openapi_server/test/test_default_controller.py