This repository was archived by the owner on Dec 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
87 lines (83 loc) · 3.82 KB
/
Jenkinsfile
File metadata and controls
87 lines (83 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
pipeline {
agent {
docker {
image 'boisvert/python-build'
args '-v /var/run/docker.sock:/var/run/docker.sock -u root'
}
}
environment {
BOT_TOKEN = credentials('alphagamebot-token')
DISCORD_CLIENT_ID = 946533554953809930
DISCORD_CLIENT_SECRET = credentials('alphagamebot-client-secret')
DOCKER_TOKEN = credentials('alphagamedev-docker-token')
AGB_VERSION = sh(returnStdout: true, script: "cat webui.json | jq '.VERSION' -cMr").trim()
COMMIT_MESSAGE = sh(script: 'git log -1 --pretty=%B ${GIT_COMMIT}', returnStdout: true).trim()
JENKINS_DISCORD_WEBHOOK = credentials('discord-jenkins-webhook')
// MySQL stuff
MYSQL_HOST = "hubby.internal"
MYSQL_DATABASE = "alphagamebot"
MYSQL_USER = "alphagamebot"
MYSQL_PASSWORD = credentials('alphagamebot-mysql-password')
DOCKER_IMAGE = "alphagamedev/alphagamebot:webui-$AGB_VERSION"
}
stages {
stage('build') {
steps {
// debug if necessary
// sh 'printenv'
echo "Building"
// 8/1/2024 -> No Cache was added because of the fact that Pycord will never update :/
// ----------> If you know a better way, please make a pull request!
sh 'docker build -t $DOCKER_IMAGE \
--build-arg COMMIT_MESSAGE="$COMMIT_MESSAGE" \
--build-arg BUILD_NUMBER="$BUILD_NuiUMBER" \
--build-arg BRANCH_NAME="$BRANCH_NAME" \
--no-cache .'
}
}
stage('push') {
when {
// We ONLY want to push Docker images when we are in the master branch!
branch 'master'
}
steps {
echo "Pushing image to Docker Hub"
sh 'echo $DOCKER_TOKEN | docker login -u alphagamedev --password-stdin'
sh 'docker tag $DOCKER_IMAGE alphagamedev/alphagamebot:webui-latest' // point tag latest to most recent version
sh 'docker push $DOCKER_IMAGE' // push tag latest version
sh 'docker push alphagamedev/alphagamebot:webui-latest' // push tag latest
sh 'docker logout'
}
}
stage('deploy') {
steps {
// conditionally deploy
sh "docker container stop alphagamebot-webui || true"
sh "docker container rm alphagamebot-webui || true"
sh "docker run -d \
--name alphagamebot-webui \
-e BOT_TOKEN -e BUILD_NUMBER -e DISCORD_CLIENT_ID -e DISCORD_CLIENT_SECRET \
-e MYSQL_HOST -e MYSQL_DATABASE -e MYSQL_USER -e MYSQL_PASSWORD \
-e GIT_COMMIT --restart=always -p 5600:5000 \
$DOCKER_IMAGE flask run -h 0.0.0.0"
}
}
} // stages
post {
always {
script {
def buildStatus = currentBuild.currentResult ?: 'SUCCESS'
def discordTitle = "${env.JOB_NAME} - Build #${env.BUILD_NUMBER} ${buildStatus}"
def discordDescription = "Commit: ${env.GIT_COMMIT}\nBranch: ${env.BRANCH_NAME}\nBuild URL: ${env.BUILD_URL}"
discordSend(
webhookURL: env.JENKINS_DISCORD_WEBHOOK,
title: discordTitle,
description: discordDescription,
link: env.BUILD_URL,
result: buildStatus
)
}
sh "docker run --rm -i --name agb-webui-postdeploy-healthcheck -e JENKINS_DISCORD_WEBHOOK $DOCKER_IMAGE python3 scripts/healthcheck-postdeployment.py"
}
}
}