# Deployment

## Introduction

We have a few custom services running on our services, custom in the sense that they are programmed from scratch and continually developed. This deployment-system allows us to test, ship new code, and restart the service automatically.

Our deployment-system is a set of custom bash-scripts which run on our server and are triggered from github, where we store our code.

The deployment is triggered at the end of a successfully run testing chain which is built with github actions.

## Step by Step: How to deploy a new service

In order to explain the deployment chain we will bring forth all the steps needed to deploy a new service with this system.

##

### -. Preconditions

{% hint style="success" %}

1. your sourcecode has its own repository within our github organization.
2. the repository is public
3. the repository has access to our self-hosted action runner.\
   (please ask an organization-owner to grant this access)
   {% endhint %}

### I. Creating a github workflow

In your repository go to tab **Actions** and setup the **Deploy to Angrezi Servers** workflow.&#x20;

<div align="left"><img src="https://1185056148-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LZz-gDif_VD8dauQ2-7%2F-MD54kumdvo-xv7_d6jx%2F-MD55-AImGPRRlr5ftDl%2FScreenshot%202020-07-25%20at%2015.09.42.png?alt=media&#x26;token=0219ecfc-811c-4dff-bad1-c792c8c1d29b" alt="Click &#x22;Set up this workflow&#x22; and commit the new file"></div>

You dont need to change anything here but can add further steps to this workflow for example to build and test your application.&#x20;

{% hint style="info" %}
Have a look at other angrezi-services to better understand \
how we use github actions.
{% endhint %}

### II. Setting up the .environment folder

Our deployment expects a `.environment` folder to be present in the root folder of your repository.\
This folder contains all files which are bound to angrezis server environment. \
Usually systemd-service files, other configuration and a deploy script are situated here.

### III. Creating a Deploy-script

Create a file `./environment/deploy.sh`&#x20;

This file well be automatically called at the end of a successful github-action workflow. \
You have access to  a few environment variables in your script:

| DEPLOY\_REPO\_NAME |                               |
| ------------------ | ----------------------------- |
|                    | # accessible var DEPLOY\_DEST |
|                    | # accessible var DEPLOY\_FROM |

### IV. Setting up the service on angrezi-server

Log in to server.radioangrezi.de and run `sudo setup-service [service-name]` .\
this will copy all the environment-files into `/opt/services/[service-name]` and symlink a few known configuration files automatically.

**.service** will be linked and enabled as a systemd service.\
\&#xNAN;**.monit-conf** will be linked as a monit config file.

{% hint style="info" %}
You have to link all other configuration files manually.
{% endhint %}

{% hint style="info" %}
Each time you make changes to files in `.environment/` you have to call `setup-service` again for your changes to take effect. \
This is a security measure.
{% endhint %}

### V. Push Code-changes to your repository
