81e4bc8a9e810c6d61057cf438d161bf5fe86933
[infra/tools.git] / infra / jenkins / slave-setup / docker-slave / Dockerfile
1 # ============LICENSE_START=======================================================
2 #  Copyright (C) 2019 The Nordix Foundation. All rights reserved.
3 # ================================================================================
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 # SPDX-License-Identifier: Apache-2.0
17 # ============LICENSE_END=========================================================
18
19 #-------------------------------------------------------------------------------
20 # This Dockerfile is used for building container images to
21 # use as Jenkins Slaves for Nordix Infra. The image is configured
22 # and tested for running
23 #   - Jenkins Job Builder Verify and Merge jobs using tox
24 #   - Cloud Infra Engine ansible-lint, yamllist, and shellcheck using tox
25 #   - ONAP report generation
26 #
27 # The image built using this Dockerfile is currently being stored on Docker Hub
28 # with the name nordixorg/infra-tools-docker-slave-ubuntu1804 which can be seen
29 # using the link below.
30 #   https://hub.docker.com/repository/docker/nordixorg/infra-tools-docker-slave-ubuntu1804
31 # The images are automatically attached to Jenkins as slaves using Jenkins
32 # Docker plugin with a name that looks like infra-ubuntu1804-<random_characters>
33 #
34 # In order to use this image as slave for your jobs, you need to use label
35 # infra-tools-docker-slave-ubuntu1804 so Jenkins schedules your job on this slave
36 # which gets provisioned by Jenkins Docker plugin. Please note that it takes few
37 # seconds before the slave becomes ready and job starts running.
38 #-------------------------------------------------------------------------------
39 FROM jenkins/jnlp-slave:latest-jdk11
40 USER root
41 # we need few basic packages in order to use base image as Jenkins slave
42 RUN apt update
43 RUN apt upgrade -o Dpkg::Options::=--force-confdef -o \
44     Dpkg::Options::=--force-confnew -q=3 -y
45 RUN apt install -o Dpkg::Options::=--force-confdef -o \
46     Dpkg::Options::=--force-confnew -q=3 -y git vim sudo \
47     software-properties-common wget jq gnupg
48 # add ubuntu repos for python3.6-minimal and the key
49 RUN add-apt-repository 'deb [arch=amd64] http://archive.ubuntu.com/ubuntu bionic main'
50 RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 3B4FE6ACC0B21F32
51 RUN apt update
52 # we need yq for ONAP report generation
53 RUN wget -O /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/3.3.0/yq_linux_amd64
54 RUN chmod +x /usr/local/bin/yq
55 # we install system packages as part of Jenkins verify jobs so
56 # jenkins user needs to be able to run sudo
57 RUN usermod -aG sudo jenkins
58 # without tty
59 RUN sed -i "s/^Defaults.*env_reset/#&\nDefaults:jenkins  \!requiretty/" /etc/sudoers
60 # and without password
61 RUN sed -i "s/^%sudo.*ALL/%sudo  ALL=(ALL:ALL)   NOPASSWD: ALL/" /etc/sudoers
62 # switch back to jenkins user
63 USER jenkins
64 # create slave_root folder same as what we use on regular slaves
65 RUN mkdir -p /home/jenkins/nordix/slave_root