feat: jenkins server
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
FROM jenkins/jenkins:2.541.3-jdk17
|
||||
|
||||
USER root
|
||||
RUN apt-get update && apt-get install -y curl git && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
USER jenkins
|
||||
|
||||
RUN jenkins-plugin-cli --plugins \
|
||||
configuration-as-code \
|
||||
credentials-binding \
|
||||
git \
|
||||
workflow-aggregator \
|
||||
job-dsl \
|
||||
pipeline-utility-steps
|
||||
|
||||
COPY jenkins.yaml /usr/share/jenkins/ref/jenkins.yaml
|
||||
ENV CASC_JENKINS_CONFIG=/usr/share/jenkins/ref/jenkins.yaml
|
||||
@@ -0,0 +1,81 @@
|
||||
#!/bin/sh
|
||||
|
||||
### UPDATE SOFTWARE
|
||||
SERVER=186.67.82.140
|
||||
CUSTOMER=$1
|
||||
cat <<EOF > /tmp/rclone.conf
|
||||
[minio]
|
||||
type = s3
|
||||
provider = Minio
|
||||
access_key_id = minioadmin
|
||||
secret_access_key = LIGTNbUgQr
|
||||
endpoint = http://$SERVER:9000
|
||||
region = us-east-1
|
||||
acl = private
|
||||
EOF
|
||||
rclone --config /tmp/rclone.conf sync minio:$CUSTOMER /opt/sco/ --exclude "backend/docker/data/**" --progress --verbose
|
||||
find /opt/sco/ -type d -exec chmod 755 {} \;
|
||||
find /opt/sco/ -type f -exec chmod 644 {} \;
|
||||
chmod -R 755 /opt/sco/frontend/
|
||||
|
||||
### TMP FOLDER
|
||||
cp /usr/lib/tmpfiles.d/fs-tmp.conf /etc/tmpfiles.d/
|
||||
echo "D /tmp 1777 root root -" > /etc/tmpfiles.d/fs-tmp.conf
|
||||
|
||||
### SERVICE
|
||||
find /opt/sco/resources/services/ -type f -exec sh -c 'cp "$1" "/etc/systemd/system/$(basename "$1")"' _ {} \;
|
||||
find /opt/sco/resources/services/ -type f -exec sh -c 'systemctl enable "$(basename "$1")"' _ {} \;
|
||||
systemctl daemon-reload
|
||||
|
||||
### AUTOSTART
|
||||
rsync -a --delete /opt/sco/resources/autostart/ /home/sco/.config/autostart/
|
||||
chown -R sco:users /home/sco/.config/autostart/*
|
||||
chmod -R 644 /home/sco/.config/autostart/*
|
||||
|
||||
### CRONTAB
|
||||
crontab -u root /opt/sco/resources/crontab/root.txt
|
||||
crontab -u sco /opt/sco/resources/crontab/sco.txt
|
||||
|
||||
### PYTHON
|
||||
find /opt/sco/resources/python/ -type d -iname "packages" | while read packages_dir; do
|
||||
parent_dir=$(dirname "$packages_dir")
|
||||
req_file="$parent_dir/requirements.txt"
|
||||
if [ -f "$req_file" ]; then
|
||||
pip install -q --no-index --find-links="$packages_dir" -r "$req_file"
|
||||
fi
|
||||
done
|
||||
|
||||
### DOCKER IMAGES
|
||||
mkdir -p /tmp/images/
|
||||
find /opt/sco/resources/images/ -type f -name '*.gz' -exec sh -c 'gunzip -c "$1" > /tmp/images/"$(basename "${1%.gz}")"' _ {} \;
|
||||
find /tmp/images/ -type f -iname "*.tar" -exec docker load -i {} \;
|
||||
|
||||
### INIT CPI-SERVER DATABASES AND LOGS FOLDERS
|
||||
mkdir -p /opt/sco/backend/docker/data/cpi-server/database
|
||||
mkdir -p /opt/sco/backend/docker/data/cpi-server/logs/devices
|
||||
mkdir -p /opt/sco/backend/docker/data/cpi-server/logs/service
|
||||
touch /opt/sco/backend/docker/data/cpi-server/database/configuration.db
|
||||
touch /opt/sco/backend/docker/data/cpi-server/database/connectivity.db
|
||||
touch /opt/sco/backend/docker/data/cpi-server/database/Identity.db
|
||||
touch /opt/sco/backend/docker/data/cpi-server/database/transaction.db
|
||||
touch /opt/sco/backend/docker/data/cpi-server/database/trialdata.db
|
||||
|
||||
### INIT SYMETRIC CONFIGURATION FILE
|
||||
mkdir -p /opt/sco/backend/docker/data/symmetric
|
||||
if [ ! -f /opt/sco/backend/docker/data/symmetric/engine.properties ]; then
|
||||
LOCAL_NODE=$(hostname)
|
||||
LOCAL_IP=$(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
|
||||
cat <<EOF > /opt/sco/backend/docker/data/symmetric/engine.properties
|
||||
engine.name=$LOCAL_NODE
|
||||
group.id=fullmesh
|
||||
external.id=$LOCAL_NODE
|
||||
db.driver=com.mysql.cj.jdbc.Driver
|
||||
db.url=jdbc:mysql://$LOCAL_IP:3306/sco
|
||||
db.user=root
|
||||
db.password=U2qs&U6LA9U2
|
||||
registration.url=
|
||||
sync.url=http://$LOCAL_IP:31415/sync/$LOCAL_NODE
|
||||
start.pulled.job=true
|
||||
job.purge.period.time.ms=7200000
|
||||
EOF
|
||||
fi
|
||||
@@ -0,0 +1,160 @@
|
||||
jenkins:
|
||||
numExecutors: 2
|
||||
authorizationStrategy:
|
||||
loggedInUsersCanDoAnything:
|
||||
allowAnonymousRead: false
|
||||
securityRealm:
|
||||
local:
|
||||
allowsSignup: false
|
||||
users:
|
||||
- id: admin
|
||||
password: H0l4mund0!
|
||||
|
||||
# Agentes permanentes (inbound/JNLP): cada SCO conecta outbound a Jenkins.
|
||||
# Nombre = identificador en Jenkins. Label "sco" agrupa todos los SCOs,
|
||||
# luego cliente (ralph) y tienda (yabucoa / san-lorenzo / rio-grande).
|
||||
nodes:
|
||||
- permanent:
|
||||
name: "ralph-yabucoa-sco02"
|
||||
labelString: "sco ralph yabucoa"
|
||||
remoteFS: "/opt/jenkins-agent"
|
||||
numExecutors: 1
|
||||
retentionStrategy: "always"
|
||||
launcher:
|
||||
inbound: {}
|
||||
- permanent:
|
||||
name: "ralph-yabucoa-sco03"
|
||||
labelString: "sco ralph yabucoa"
|
||||
remoteFS: "/opt/jenkins-agent"
|
||||
numExecutors: 1
|
||||
retentionStrategy: "always"
|
||||
launcher:
|
||||
inbound: {}
|
||||
- permanent:
|
||||
name: "ralph-yabucoa-sco04"
|
||||
labelString: "sco ralph yabucoa"
|
||||
remoteFS: "/opt/jenkins-agent"
|
||||
numExecutors: 1
|
||||
retentionStrategy: "always"
|
||||
launcher:
|
||||
inbound: {}
|
||||
- permanent:
|
||||
name: "ralph-yabucoa-sco05"
|
||||
labelString: "sco ralph yabucoa"
|
||||
remoteFS: "/opt/jenkins-agent"
|
||||
numExecutors: 1
|
||||
retentionStrategy: "always"
|
||||
launcher:
|
||||
inbound: {}
|
||||
- permanent:
|
||||
name: "ralph-yabucoa-sco06"
|
||||
labelString: "sco ralph yabucoa"
|
||||
remoteFS: "/opt/jenkins-agent"
|
||||
numExecutors: 1
|
||||
retentionStrategy: "always"
|
||||
launcher:
|
||||
inbound: {}
|
||||
- permanent:
|
||||
name: "ralph-yabucoa-sco07"
|
||||
labelString: "sco ralph yabucoa"
|
||||
remoteFS: "/opt/jenkins-agent"
|
||||
numExecutors: 1
|
||||
retentionStrategy: "always"
|
||||
launcher:
|
||||
inbound: {}
|
||||
- permanent:
|
||||
name: "ralph-san-lorenzo-sco03"
|
||||
labelString: "sco ralph san-lorenzo"
|
||||
remoteFS: "/opt/jenkins-agent"
|
||||
numExecutors: 1
|
||||
retentionStrategy: "always"
|
||||
launcher:
|
||||
inbound: {}
|
||||
- permanent:
|
||||
name: "ralph-san-lorenzo-sco04"
|
||||
labelString: "sco ralph san-lorenzo"
|
||||
remoteFS: "/opt/jenkins-agent"
|
||||
numExecutors: 1
|
||||
retentionStrategy: "always"
|
||||
launcher:
|
||||
inbound: {}
|
||||
- permanent:
|
||||
name: "ralph-san-lorenzo-sco05"
|
||||
labelString: "sco ralph san-lorenzo"
|
||||
remoteFS: "/opt/jenkins-agent"
|
||||
numExecutors: 1
|
||||
retentionStrategy: "always"
|
||||
launcher:
|
||||
inbound: {}
|
||||
- permanent:
|
||||
name: "ralph-san-lorenzo-sco06"
|
||||
labelString: "sco ralph san-lorenzo"
|
||||
remoteFS: "/opt/jenkins-agent"
|
||||
numExecutors: 1
|
||||
retentionStrategy: "always"
|
||||
launcher:
|
||||
inbound: {}
|
||||
- permanent:
|
||||
name: "ralph-rio-grande-sco01"
|
||||
labelString: "sco ralph rio-grande"
|
||||
remoteFS: "/opt/jenkins-agent"
|
||||
numExecutors: 1
|
||||
retentionStrategy: "always"
|
||||
launcher:
|
||||
inbound: {}
|
||||
- permanent:
|
||||
name: "ralph-rio-grande-sco02"
|
||||
labelString: "sco ralph rio-grande"
|
||||
remoteFS: "/opt/jenkins-agent"
|
||||
numExecutors: 1
|
||||
retentionStrategy: "always"
|
||||
launcher:
|
||||
inbound: {}
|
||||
- permanent:
|
||||
name: "ralph-rio-grande-sco03"
|
||||
labelString: "sco ralph rio-grande"
|
||||
remoteFS: "/opt/jenkins-agent"
|
||||
numExecutors: 1
|
||||
retentionStrategy: "always"
|
||||
launcher:
|
||||
inbound: {}
|
||||
- permanent:
|
||||
name: "ralph-rio-grande-sco04"
|
||||
labelString: "sco ralph rio-grande"
|
||||
remoteFS: "/opt/jenkins-agent"
|
||||
numExecutors: 1
|
||||
retentionStrategy: "always"
|
||||
launcher:
|
||||
inbound: {}
|
||||
- permanent:
|
||||
name: "ralph-rio-grande-sco05"
|
||||
labelString: "sco ralph rio-grande"
|
||||
remoteFS: "/opt/jenkins-agent"
|
||||
numExecutors: 1
|
||||
retentionStrategy: "always"
|
||||
launcher:
|
||||
inbound: {}
|
||||
- permanent:
|
||||
name: "ralph-rio-grande-sco06"
|
||||
labelString: "sco ralph rio-grande"
|
||||
remoteFS: "/opt/jenkins-agent"
|
||||
numExecutors: 1
|
||||
retentionStrategy: "always"
|
||||
launcher:
|
||||
inbound: {}
|
||||
|
||||
security:
|
||||
globalJobDslSecurityConfiguration:
|
||||
useScriptSecurity: false
|
||||
|
||||
jobs:
|
||||
- script: |
|
||||
pipelineJob('deploy-ralph') {
|
||||
description('Deploy de install.sh a los SCOs de Ralph en la tienda seleccionada.')
|
||||
definition {
|
||||
cps {
|
||||
script(new File('/opt/jenkins/Jenkinsfile.ralph').text)
|
||||
sandbox(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
pipeline {
|
||||
agent none
|
||||
|
||||
parameters {
|
||||
choice(
|
||||
name: 'TIENDA',
|
||||
choices: ['yabucoa', 'san-lorenzo', 'rio-grande'],
|
||||
description: 'Tienda destino'
|
||||
)
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Preparar scripts') {
|
||||
agent { label 'built-in' }
|
||||
steps {
|
||||
sh 'cp /opt/deploy/install.sh .'
|
||||
stash name: 'scripts', includes: 'install.sh'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy') {
|
||||
agent { label 'built-in' }
|
||||
steps {
|
||||
script {
|
||||
def labelExpr = "ralph && ${params.TIENDA}"
|
||||
def nodes = nodesByLabel(label: labelExpr, offline: false)
|
||||
if (nodes.isEmpty()) {
|
||||
error "No hay nodos online con el label: ${labelExpr}"
|
||||
}
|
||||
def deployStages = nodes.collectEntries { nodeName ->
|
||||
["Deploy ${nodeName}": {
|
||||
node(nodeName) {
|
||||
unstash 'scripts'
|
||||
sh "bash install.sh 'ralph'"
|
||||
sh 'cat ~/sco-app/installed.txt'
|
||||
}
|
||||
}]
|
||||
}
|
||||
parallel deployStages
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user