[TempDoc] How to deploy .NET Apps on OnePipe Infrastructure
This will serve as a guide on steps required to add a .NET based application on our CI/CD pipeline viz-a-viz infrastructure.
The following assumptions are made
1) There’s an existing .NET project.
2) The project and its dependencies can run on a Linux environment (possibly if it's based on .NET core)
3) The project is already added to our Bitbucket repository.
Step 1: Adding a Dockerfile
to the Project
This is required to build an image of the application and its dependencies, which is then published to a private docker repository and pulled to run in our environment.
Here’s a typical folder structure for a .NET Project
/src
└── package.json
└── MYAPP.APIPROJECT
└── MYAPP.APIPROJECT.csproj
└── Dockerfile
└── MYAPP.API.sln
Content of the DockerFile
Note : Change the name of the Project/Folder and Solution to match your application’s
FROM microsoft/dotnet:2.2-sdk AS base
WORKDIR /app
EXPOSE 80
# copy everything and build the project
COPY . .
WORKDIR /app/MYAPP.APIPROJECT
RUN dotnet restore
# copy and publish app and libraries
WORKDIR /app/
COPY MYAPP.APIPROJECT/. ./myapp/
WORKDIR /app/myapp
RUN dotnet publish --no-dependencies MYAPP.APIPROJECT.csproj -c Release -o out
# build runtime image
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS build-env
ARG BUILD_NUMBER_INIT=0
ENV BUILD_NUMBER=$BUILD_NUMBER_INIT
WORKDIR /app
COPY --from=base /app/myapp/out .
# SET entrypoint to run
ENTRYPOINT ["dotnet", "MYAPP.APIPROJECT.dll"]
Note : Ensure that your app runs on port 80
Step 2: Add Bitbucket Pipeline YAML file.
To allow the application integrate to Bitbucket pipeline which we use in our CI flow, proceed to adding the bitbucket-pipelines.yml
file to the solution root.
/src
└── package.json
└── MYAPP.APIPROJECT
└── MYAPP.APIPROJECT.csproj
└── DockerFile
└── bitbucket-pipelines.yml
└── MYAPP.API.sln
Content of bitbucket-pipelines.yml
Brief explanation of the content of the bitbucket-pipeline.yml file
Step 3: Setting up Application for CI/CD integration
This should be done after pushing the changes on the previous steps to the repository.
From the Repository go to
Settings -> Pipeplines -> Settings
toggleEnable Pipeples
So that it becomes green to show that pipelines are now enabled.From
Settings -> Pipelines -> Repository Variables
Set the following Variables
Step 4: Creating the app on the central OnePipe Repository
Now that we have our application dockerised, pushed to our pipelines enabled repository, the next step is to add the app to OnePipe’s continuous deployment workflow. The whole configuration for this is done in a separate repository https://bitbucket.org/onepipe/eshu/src/master/ .
Pull the master branch of this Repo into your local machine
Checkout to a new
feature/my_app
branch and create a new service by adding a key to the/eshu/config/services.py
file as illustrated below.
Ensure that the name of your app is the key to this object (eg my_app
) also the parameter in the image
key should match. Note the routes has dev
, staging
and live
ensure you set your url as {app}.{env}.onepipe.io
If your app is an API, set the type
object to api
else ui
. Your app must also have a /health
endpoint as illustrated in the health_url
above and this endpoint must return Status code 200
. So create an endpoint in your app to match this.
Step 5: Setting up Environment Variables
After you have added your app to the services. you can commit your changes. Next is to setup environment variables for our app. edit the /eshu/config/env.py
so that you can create your own environment variables for all the three environments as illustrated below.
Step 6: Finishing Up
Once you have pushed your branch to the eshu repo, ensure you add multiple reviews and your branch gets merged. Once your branch has gotten merged. Return to your own repo after 5 minutes (in this case our my_app
) repo and attempt to retry your pipelines - they should be successful by now.
Going forward to deploy your app to development make sure you push a branch with feature/*
format to your repo. This type of branch will automatically deploy and after about 5 minutes or more you should be able to see the changes.