-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
58 lines (57 loc) · 2.1 KB
/
Jenkinsfile
File metadata and controls
58 lines (57 loc) · 2.1 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
pipeline {
agent any
environment {
GITHUB_TOKEN=credentials('github-container')
IP=credentials('yandex-apps-ip')
IMAGE_NAME='siberiacancode/juniors-bootcamp-portal'
IMAGE_VERSION='latest'
PORT='3011'
}
stages {
stage('cleanup') {
steps {
sh 'docker system prune -a --volumes --force'
}
}
stage('build image') {
steps {
sh 'docker build -t $IMAGE_NAME:$IMAGE_VERSION .'
}
}
stage('login to GHCR') {
steps {
sh 'echo $GITHUB_TOKEN_PSW | docker login ghcr.io -u $GITHUB_TOKEN_USR --password-stdin'
}
}
stage('tag image') {
steps {
sh 'docker tag $IMAGE_NAME:$IMAGE_VERSION ghcr.io/$IMAGE_NAME:$IMAGE_VERSION'
}
}
stage('push image') {
steps {
sh 'docker push ghcr.io/$IMAGE_NAME:$IMAGE_VERSION'
}
}
stage('deploy') {
steps {
withCredentials(bindings: [sshUserPrivateKey(credentialsId: 'yandex-apps-container', keyFileVariable: 'SSH_PRIVATE_KEY', usernameVariable: 'SSH_USERNAME')]) {
sh 'echo $SSH_USERNAME'
sh 'install -m 600 -D /dev/null ~/.ssh/id_rsa'
sh 'rm ~/.ssh/id_rsa'
sh 'cp -i $SSH_PRIVATE_KEY ~/.ssh/id_rsa'
sh 'ssh -o "StrictHostKeyChecking=no" $SSH_USERNAME@$IP \
"sudo docker login ghcr.io -u $GITHUB_TOKEN_USR --password $GITHUB_TOKEN_PSW &&\
sudo docker rm -f juniors-bootcamp-portal &&\
sudo docker pull ghcr.io/siberiacancode/juniors-bootcamp-portal:latest &&\
sudo docker run --restart=always --name juniors-bootcamp-portal -d -p $PORT:$PORT -e PORT=$PORT --network juniors-bootcamp ghcr.io/siberiacancode/juniors-bootcamp-portal:latest"'
}
}
}
}
post {
always {
sh 'docker logout'
}
}
}