Skip to content

Commit 3b136da

Browse files
authored
Merge pull request #25 from rpitonak/add-ci
Setup CI
2 parents 2f110b4 + 05bc922 commit 3b136da

File tree

4 files changed

+131
-2
lines changed

4 files changed

+131
-2
lines changed

Jenkinsfile

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
def onmyduffynode(script){
2+
ansiColor('xterm'){
3+
timestamps{
4+
sh 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l root ${DUFFY_NODE}.ci.centos.org -t \"export REPO=${REPO}; export BRANCH=${BRANCH};\" "' + script + '"'
5+
}
6+
}
7+
}
8+
9+
def synctoduffynode(source)
10+
{
11+
sh 'scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r ' + source + " " + "root@" + "${DUFFY_NODE}.ci.centos.org:~/"
12+
}
13+
14+
node('userspace-containerization'){
15+
16+
stage('Checkout'){
17+
checkout scm
18+
}
19+
20+
stage('Build'){
21+
try{
22+
stage ("Allocate node"){
23+
env.CICO_API_KEY = readFile("${env.HOME}/duffy.key").trim()
24+
duffy_rtn=sh(
25+
script: "cico --debug node get --arch x86_64 -f value -c hostname -c comment",
26+
returnStdout: true
27+
).trim().tokenize(' ')
28+
env.DUFFY_NODE=duffy_rtn[0]
29+
env.DUFFY_SSID=duffy_rtn[1]
30+
}
31+
32+
stage ("Setup"){
33+
onmyduffynode "yum -y install epel-release"
34+
onmyduffynode "yum -y install python36-pip python36-devel rpmdevtools docker ansible"
35+
onmyduffynode "yum -y remove git"
36+
onmyduffynode "curl -o /etc/yum.repos.d/git-epel-7.repo https://copr.fedorainfracloud.org/coprs/g/git-maint/git/repo/epel-7/group_git-maint-git-epel-7.repo"
37+
onmyduffynode "yum -y install git-core"
38+
onmyduffynode "pip3 install pre-commit"
39+
onmyduffynode "pip3 install --upgrade pip"
40+
onmyduffynode "export RPM_PY_SYS=true"
41+
onmyduffynode "yum install -y rebase-helper krb5-libs krb5-devel krb5-workstation"
42+
synctoduffynode "./." // copy all source files (hidden too, we need .git/)
43+
}
44+
45+
stage ("Setup Openshift Cluster"){
46+
onmyduffynode "ansible-playbook -v -i localhost, --connection=local ./files/install-openshift.yaml"
47+
}
48+
49+
stage ("Image build"){
50+
onmyduffynode "make test-image-build"
51+
}
52+
53+
stage ("Tests"){
54+
onmyduffynode "pytest --color=yes --verbose --showlocals ./tests"
55+
}
56+
57+
stage ("Linters"){
58+
onmyduffynode "pre-commit run --all-files"
59+
}
60+
61+
} catch (e) {
62+
currentBuild.result = "FAILURE"
63+
throw e
64+
} finally {
65+
stage("Cleanup"){
66+
sh 'cico node done ${DUFFY_SSID}'
67+
}
68+
}
69+
}
70+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Sandcastle
1+
# Sandcastle [![Build Status](https://ci.centos.org/job/sandcastle-master/badge/icon)](https://ci.centos.org/job/sandcastle-master/)
22

33
Run untrusted code in a castle (OpenShift pod), which stands in a sandbox.
44

files/install-openshift.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
- name: Install dependencies for sandcastle.
3+
hosts: all
4+
tasks:
5+
- name: Install basic utilities which should be in a sandbox.
6+
yum:
7+
name:
8+
- git
9+
- rpmdevtools
10+
- docker
11+
state: present
12+
- name:
13+
pip:
14+
executable: pip3
15+
requirements: "{{ lookup('env','PWD') }}/tests/requirements.txt"
16+
- name: Install packit
17+
pip:
18+
name:
19+
- packitos
20+
- kubernetes==8.0.0
21+
- pytest
22+
- flexmock
23+
executable: pip3
24+
- name: Disable SELinux
25+
command: setenforce 0
26+
- name: Disable firewall
27+
command: systemctl stop firewalld # firewall on CentOS does not allow docker login into OpenShift registry
28+
- name: Start docker deamon
29+
command: systemctl start docker
30+
- name: Create docker deamon config
31+
file:
32+
path: /etc/docker/daemon.json
33+
state: touch
34+
- name: Add OpenShift insecure registry into docker deamon config
35+
copy:
36+
content: |
37+
{"insecure-registries" : [ "172.30.0.0/16" ]}
38+
dest: /etc/docker/daemon.json
39+
- name: Restart docker because config has changed
40+
command: systemctl restart docker
41+
- name: Install OpenShift server
42+
yum:
43+
name:
44+
- centos-release-openshift-origin310
45+
state: present
46+
- name: Install OpenShift client
47+
yum:
48+
name:
49+
- origin-clients
50+
state: present
51+
- name: Start Openshift cluster
52+
command: oc cluster up --base-dir=/tmp
53+
environment:
54+
PATH: "{{ ansible_env.PATH}}:/usr/local/bin"
55+
DOCKER_CONFIG: "/etc/docker/daemon.json"
56+
57+
# https://github.com/packit-service/sandcastle#developing-sandcastle
58+
- name: Add permissions for service account
59+
command: oc adm policy add-role-to-user edit system:serviceaccount:myproject:default

tests/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
kubernetes
1+
kubernetes==8.0.0
22
flexmock
33
pytest

0 commit comments

Comments
 (0)