Skip to content

Commit

Permalink
Merge pull request #368 from rpitonak/ci-fix
Browse files Browse the repository at this point in the history
[CI] Use Jenkins pipeline and ansible playbooks
  • Loading branch information
TomasTomecek committed Aug 23, 2019
2 parents 08caae7 + 5eaeacc commit 17bb4a2
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 54 deletions.
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# https://editorconfig.org/

root = true

[*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
charset = utf-8

[*.py]
max_line_length = 100

[Makefile]
indent_style = tab

[*.{json,y{a,}ml,sh}]
indent_size = 2

[Dockerfile*]
indent_size = 2
21 changes: 15 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
FROM registry.fedoraproject.org/fedora:29
FROM registry.fedoraproject.org/fedora:30

ENV PYTHONDONTWRITEBYTECODE=yes
# ANSIBLE_STDOUT_CALLBACK - nicer output from the playbook run
ENV LANG=en_US.UTF-8 \
PYTHONDONTWRITEBYTECODE=yes \
WORKDIR=/src \
ANSIBLE_STDOUT_CALLBACK=debug

WORKDIR /src
COPY ./requirements.sh /src/
RUN ./requirements.sh && \
dnf clean all

RUN dnf install -y ansible && dnf clean all

WORKDIR /src
COPY . /src

# install all packages
RUN ansible-playbook -vv -c local -i localhost, files/install-packages.yaml \
&& dnf clean all

# install conu
RUN pip3 install .
3 changes: 0 additions & 3 deletions Dockerfile.tests
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
FROM docker.io/usercont/conu:dev

RUN dnf install -y nmap-ncat make && \
pip3 install --user -r tests/requirements.txt

# a solution to set cgroup_manager to cgroupfs since we don't have
# systemd in the container where we run tests
RUN cp /usr/share/containers/libpod.conf /etc/containers/ \
Expand Down
64 changes: 64 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
def onmyduffynode(script){
ansiColor('xterm'){
timestamps{
sh 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l root ${DUFFY_NODE}.ci.centos.org -t \"export REPO=${REPO}; export BRANCH=${BRANCH};\" "' + script + '"'
}
}
}

def synctoduffynode(source)
{
sh 'scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r ' + source + " " + "root@" + "${DUFFY_NODE}.ci.centos.org:~/"
}

node('userspace-containerization'){

stage('Checkout'){
checkout scm
}

stage('Build'){
try{
stage ("Allocate node"){
env.CICO_API_KEY = readFile("${env.HOME}/duffy.key").trim()
duffy_rtn=sh(
script: "cico --debug node get --arch x86_64 -f value -c hostname -c comment",
returnStdout: true
).trim().tokenize(' ')
env.DUFFY_NODE=duffy_rtn[0]
env.DUFFY_SSID=duffy_rtn[1]
}

stage ("Setup"){
onmyduffynode "yum -y install epel-release docker make podman rpm-build python36-pip python36-devel"
onmyduffynode "pip3 install --upgrade pip"
onmyduffynode "pip3 install pre-commit"
synctoduffynode "./." // copy all source files (hidden too, we need .git/)
}

stage ("Setup Openshift Cluster"){
make setup-oc-cluster-ci
}

stage ("Image build"){
onmyduffynode "make container-image"
}

stage ("Test image build"){
onmyduffynode "make build-test-container"
}

stage ("Run tests"){
onmyduffynode "make test-in-container"
}

} catch (e) {
currentBuild.result = "FAILURE"
throw e
} finally {
stage("Cleanup"){
sh 'cico node done ${DUFFY_SSID}'
}
}
}
}
19 changes: 9 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ DOC_EXAMPLE_PATH := "docs/source/examples"
VERSION := 0.4.0

install-requirements:
./requirements.sh
dnf install -y ansible && \
ansible-playbook -vv -c local -i localhost, files/install-packages.yaml

install-test-requirements:
./test-requirements.sh
setup-oc-cluster-ci:
yum install -y ansible && \
ansible-playbook -vv -c local -i localhost, files/install-openshift.yaml

# FIXME: run both, fail if any failed -- I am not good makefile hacker
exec-test:
cat pytest.ini
@# use it like this: `make exec-test TEST_TARGET="tests/unit/"`
PYTHONPATH=$(CURDIR) pytest-3 $(TEST_TARGET) --verbose --showlocals
PYTHONPATH=$(CURDIR) pytest $(TEST_TARGET) --verbose --showlocals

check: test
check: container-image build-test-container test-in-container docs-in-container

build-docs-container:
docker build --network host --tag=$(DOCS_IMAGE_NAME) -f ./Dockerfile.docs .
Expand All @@ -45,17 +47,14 @@ container:
build-test-container:
docker build --network host --tag=$(TEST_IMAGE_NAME) -f ./Dockerfile.tests .

# You have to run 'sudo make install-test-requirements' prior to this.
test: build-test-container test-in-container test-doc-examples

centos-ci-test: install-test-requirements container-image build-test-container test-in-container
centos-ci-test: setup-oc-cluster-ci container-image build-test-container test-in-container

test-in-container:
@# use it like this: `make test-in-container TEST_TARGET=tests/integration/test_utils.py`
$(eval kubedir := $(shell mktemp -d /tmp/tmp.conu-kube-XXXXX))
sed -e s@"${HOME}"@/root@g ${HOME}/.kube/config > $(kubedir)/config ; \
docker run \
--rm -ti \
--rm -i \
--net=host \
--privileged \
-e STORAGE_DRIVER=vfs \
Expand Down
59 changes: 59 additions & 0 deletions files/install-openshift.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
- name: Inastall dependencies needed for OpenShift
hosts: all
tasks:
- name: Install rpms.
yum:
name:
- git
- docker
state: present
- name: Put SELinux in permissive mode, logging actions that would be blocked.
selinux:
policy: targeted
state: permissive
- name: Stop service firewall, if running
systemd:
name: firewalld
state: stopped # firewall on CentOS does not allow docker login into OpenShift registry
- name: Make sure docker is running
systemd:
name: docker
state: started
- name: Create docker deamon config
file:
path: /etc/docker/daemon.json
state: touch
- name: Add OpenShift insecure registry into docker deamon config
copy:
content: |
{"insecure-registries" : [ "172.30.0.0/16" ]}
dest: /etc/docker/daemon.json
- name: Restart docker because config has changed
systemd:
state: restarted
daemon_reload: yes
name: docker
- name: Install OpenShift server
yum:
name:
- centos-release-openshift-origin310
state: present
- name: Install OpenShift client
yum:
name:
- origin-clients
state: present
- name: Start Openshift cluster
command: oc cluster up --base-dir=/tmp
environment:
PATH: "{{ ansible_env.PATH}}:/usr/local/bin"
DOCKER_CONFIG: "/etc/docker/daemon.json"

- name: Add permissions for developer account
command: "{{ item }}"
with_items:
- oc login -u system:admin
- oc adm policy add-cluster-role-to-user admin developer
- oc adm policy add-cluster-role-to-user cluster-admin developer
- oc login -u developer -p developer
29 changes: 29 additions & 0 deletions files/install-packages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
- name: Install dependencies for conu.
hosts: all
tasks:
- name: Install all RPM packages needed to hack on conu.
dnf:
name:
- make
- nmap-ncat
- docker
- libselinux-utils
- source-to-image
- python3-pip
- python3-pyxattr
- gcc
- python3-devel
- podman
- skopeo
- origin-clients
state: present
tags:
- conu-deps

- name: Install test requirements
pip:
executable: /usr/bin/pip3
requirements: "{{ lookup('env','PWD') }}/tests/requirements.txt"
tags:
- conu-test-deps
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
requests
six
docker
kubernetes
kubernetes==8.0.0
pytest
34 changes: 0 additions & 34 deletions test-requirements.sh

This file was deleted.

0 comments on commit 17bb4a2

Please sign in to comment.