Skip to content

VI. Deployment

Frederik Wulf edited this page May 5, 2023 · 5 revisions

This page will give a brief overview of the deployment of the application and how to use it. It will cover the automatic deployment with Github Actions or the manual local deployment.

Content

  1. NuGet Packages
  2. Docker Images

NuGet Packages

NuGet Package

As part of the CI/CD pipeline, the projects shared libraries are published as NuGet packages. The packages are published to the GitHub Package Registry.

How to use the packages

To use the packages, there are two ways. Use the packages that are published to the GitHub Package Registry or build and pack the NuGet packages locally.

Use the packages from GitHub Package Registry

To use the packages from the GitHub Package Registry, add the GitHub Package Registry as a package source. To do this, add the following configuration to your NuGet configuration file. The configuration file is located at %appdata%\NuGet\NuGet.Config on Windows and ~/.nuget/NuGet/NuGet.Config on Linux.

Run dotnet nuget add source https://nuget.pkg.github.com/fredyyy998/index.json -n github -u <username> -p <access_key> to add the source to the NuGet.Config or

Add the following code:

<configuration>
    ... other configuration
    <packageSources>
        ... other sources
        <add key="github" value="https://nuget.pkg.github.com/fredyyy998/index.json" />
    </packageSources>

    <packageSourceCredentials>
        <github>
            <add key="Username" value="<username>" />
            <add key="ClearTextPassword" value="<access_key>" />
        </github>
    </packageSourceCredentials>
</configuration>

As username insert your github username. For the access_key generate a personal access token with rights to atleast read packages(read:packages). Access tokens can be generated at Settings > Developer Settings > Personal Access Tokens > Tokens classic. Read more about permissions for packages

After this setup the packages should be available in the project. Otherwise reload the NuGet packages in the NuGet package manager.

Use the packages locally

To use the packages locally, build and pack the packages locally. To do that the steps below can be followed:

  1. Go into the Common solution src/Ecommerce.Common
  2. Build the package by yourself and pack the project with dotnet pack -o <direcotry path> to some output directory
  3. Reference the local package directory in your NuGet.Config, run dotnet nuget add source <direcotry path> to add the source to the NuGet.Config or
    Add the following code:
<configuration>
    ... other configuration
    <packageSources>
        ... other sources
        <add key="Offline Packages" value="<direcotry path>" />
    </packageSources>
    
</configuration>

After any of these setups, the packages should be available in the project. Otherwise reload the NuGet packages in the NuGet package manager.

Updating the packages

To update the packages, you need to update the version in the Ecommerce.Common.csproj file. To publish the packages trigger the CI/CD pipeline NuGet Package. The pipeline will build and publish the packages to the GitHub Package Registry and the new versions of the packages will be available.

Docker Images

Docker images

The projects services are build as Docker images and published to the GitHub Container Registry. The images are build with the GitHub Actions, these must be triggered manually.

How to use the images

The packages can either be pulled from the GitHub container registry or build locally.

Use the packages from GitHub Container Registry

A single image can be used by pulling the image from the GitHub Container Registry. To do this simply run docker pull ghcr.io/fredyyy998/<service name>:<tag>. For tag is is recommended to use latest, since there is no versioning yet.

However it is simpler to start the whole application with the docker-compose file. To do this run docker-compose up. This will start the whole application with the latest images.

Use localy build images

There is also the possiblity to not use the docker images from the github repository. To use localy build images follow these steps:

  1. Have the Nuget Packages ready to use
  2. Have the database migrated like explained in the Getting Started section step 4
  3. Build every service with the command dotnet publish <service_name>.Web -c Release within the root of the service
  4. After every service is build use docker-compose -f docker-compose.local.yml up

Updating the images

To update the images, you can simply trigger the CI/CD pipeline Docker Images. The pipeline will build and publish the images to the GitHub Container Registry and the new versions of the images will be available. To use the newly published images, you need to pull the images again. You could also delete the old images for each service, and when the container start again they will pull automatically. However, there must be some manual work involved.

Clone this wiki locally