Skip to content

Commit ce38dbb

Browse files
Adding release pipeline
1 parent 3889291 commit ce38dbb

File tree

5 files changed

+129
-0
lines changed

5 files changed

+129
-0
lines changed

Dockerfile

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
2+
USER $APP_UID
3+
WORKDIR /app
4+
5+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
6+
ARG BUILD_CONFIGURATION=Release
7+
WORKDIR /src
8+
COPY ["src/SiteMonitor/SiteMonitor.csproj", "src/SiteMonitor/"]
9+
RUN dotnet restore "src/SiteMonitor/SiteMonitor.csproj"
10+
COPY src/ .
11+
WORKDIR "/src/SiteMonitor"
12+
RUN dotnet build "SiteMonitor.csproj" -c $BUILD_CONFIGURATION -o /app/build
13+
14+
FROM build AS publish
15+
ARG BUILD_CONFIGURATION=Release
16+
ARG TAG_VERSION
17+
ARG GITHUB_TOKEN
18+
ARG DESCRIPTION
19+
RUN apt-get update && apt-get dist-upgrade -y && apt-get install zip jq -y
20+
21+
# Generate the executables
22+
RUN dotnet publish "SiteMonitor.csproj" -c $BUILD_CONFIGURATION -o /app/publish/win-x64 -r win-x64
23+
RUN dotnet publish "SiteMonitor.csproj" -c $BUILD_CONFIGURATION -o /app/publish/win-x86 -r win-x86
24+
RUN cd /app/publish/win-x64 && zip -r ../windows-x64.zip *
25+
RUN cd /app/publish/win-x86 && zip -r ../windows-x86.zip *
26+
27+
# Create a tag and associate it with a release in GitHub. We don't need to check if it already exist, if it already
28+
# exists the command won't do anything.
29+
RUN curl -L \
30+
-X POST \
31+
-H "Accept: application/vnd.github+json" \
32+
-H "Authorization: Bearer $GITHUB_TOKEN" \
33+
https://api.github.com/repos/nullinside-development-group/nullinside-site-monitor/releases \
34+
-d '{"tag_name":"'$TAG_VERSION'","target_commitish":"main","name":"'$TAG_VERSION'","body":"'$DESCRIPTION'","draft":false,"prerelease":false,"generate_release_notes":false}'
35+
36+
# Upload the files to the release. We need to get the ID for the release we created first and then upload the zips.
37+
# This needs to be done in a single run command to provide the $RELEASE_ID to the rest of the commands. We don't need to
38+
# check if it already exist, if it already exists the command won't do anything.
39+
RUN export RELEASE_ID=$(curl -L \
40+
-H "Accept: application/vnd.github+json" \
41+
-H "Authorization: Bearer $GITHUB_TOKEN" \
42+
-H "X-GitHub-Api-Version: 2022-11-28" \
43+
"https://api.github.com/repos/nullinside-development-group/nullinside-site-monitor/releases/latest" \
44+
| jq .id) && \
45+
echo "Release ID: "$RELEASE_ID && \
46+
curl -L \
47+
-X POST \
48+
-H "Accept: application/vnd.github+json" \
49+
-H "Authorization: Bearer $GITHUB_TOKEN" \
50+
-H "Content-Type: application/octet-stream" \
51+
"https://uploads.github.com/repos/nullinside-development-group/nullinside-site-monitor/releases/$RELEASE_ID/assets?name=windows-x64.zip" \
52+
--data-binary "@/app/publish/windows-x64.zip" && \
53+
curl -L \
54+
-X POST \
55+
-H "Accept: application/vnd.github+json" \
56+
-H "Authorization: Bearer $GITHUB_TOKEN" \
57+
-H "Content-Type: application/octet-stream" \
58+
"https://uploads.github.com/repos/nullinside-development-group/nullinside-site-monitor/releases/$RELEASE_ID/assets?name=windows-x86.zip" \
59+
--data-binary "@/app/publish/windows-x86.zip"

Jenkinsfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
pipeline {
2+
agent any
3+
options {
4+
ansiColor('xterm')
5+
}
6+
7+
stages {
8+
stage('Checkout') {
9+
steps {
10+
git branch: env.BRANCH_NAME, credentialsId: 'GitHub PAT', url: 'https://github.com/nullinside-development-group/nullinside-site-monitor.git'
11+
}
12+
}
13+
14+
stage('Build & Deploy') {
15+
steps {
16+
withCredentials([
17+
string(credentialsId: 'GITHUB_NULLINSIDE_ORG_RELEASE_TOKEN', variable: 'GITHUB_NULLINSIDE_ORG_RELEASE_TOKEN')
18+
]) {
19+
sh """
20+
bash go.sh
21+
"""
22+
}
23+
}
24+
}
25+
}
26+
27+
post {
28+
always {
29+
cleanWs cleanWhenFailure: false, notFailBuild: true
30+
}
31+
}
32+
}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# nullinside-site-monitor
2+
3+
The purpose of this project is to check the current status of the [nullinside](https://nullinside.com) website and alert
4+
when one or more aspects of the site are down.

go.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
# If there is already a version number don't make a new one.
3+
export TAG_VERSION=$(git tag --points-at HEAD)
4+
if [[ -z "$TAG_VERSION" ]]; then
5+
# Get the latest version for the repo
6+
export CURRENT_VERSION=$(curl "https://api.github.com/repos/nullinside-development-group/nullinside-site-monitor/tags" | jq -r '.[0].name')
7+
major=1
8+
minor=0
9+
build=-1
10+
11+
# Break down the version number into it's components
12+
regex="([0-9]+).([0-9]+).([0-9]+)"
13+
if [[ $CURRENT_VERSION =~ $regex ]]; then
14+
major="${BASH_REMATCH[1]}"
15+
minor="${BASH_REMATCH[2]}"
16+
build="${BASH_REMATCH[3]}"
17+
fi
18+
19+
# Increment the build always
20+
build=$(echo $build+1 | bc)
21+
export TAG_VERSION=${major}.${minor}.${build}
22+
fi
23+
24+
docker system prune -af
25+
docker build --build-arg="TAG_VERSION=v"$TAG_VERSION --build-arg="GITHUB_TOKEN="$GITHUB_NULLINSIDE_ORG_RELEASE_TOKEN --progress=plain --no-cache .

src/SiteMonitor.sln

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
Microsoft Visual Studio Solution File, Format Version 12.00
33
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SiteMonitor", "SiteMonitor\SiteMonitor.csproj", "{9C6BE74C-22B4-4A81-91EA-32204163F8EE}"
44
EndProject
5+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionFolder", "SolutionFolder", "{9894F6E0-42A7-4A9D-96F8-8ECB2221230A}"
6+
ProjectSection(SolutionItems) = preProject
7+
..\.gitignore = ..\.gitignore
8+
..\README.md = ..\README.md
9+
..\Dockerfile = ..\Dockerfile
10+
..\go.sh = ..\go.sh
11+
..\Jenkinsfile = ..\Jenkinsfile
12+
EndProjectSection
13+
EndProject
514
Global
615
GlobalSection(SolutionConfigurationPlatforms) = preSolution
716
Debug|Any CPU = Debug|Any CPU

0 commit comments

Comments
 (0)