-
Notifications
You must be signed in to change notification settings - Fork 7
/
tf-cli
123 lines (98 loc) · 3.25 KB
/
tf-cli
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
FROM phusion/baseimage:focal-1.0.0
ENV DEBIAN_FRONTEND noninteractive
ENV HOME /root
ENV LC_ALL C.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
ENV PATH /data/testflinger-cli:$PATH
ARG ubuntu_scr
# ARG testflinger_scr
# add maas-cli PPA
RUN apt-add-repository ppa:maas/2.9 -y
# install deps & cleanup
RUN apt-get update \
&& apt-get install -y \
--no-install-recommends \
bash \
bash-completion \
sudo \
openssh-client \
build-essential \
net-tools \
iputils-ping \
iproute2 \
curl \
git \
wget \
python3 \
python3-dev \
python3-pip \
python3-virtualenv \
python3-requests \
python3-click \
maas-cli
# clean up APT
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# link python3 bin
RUN ln -s /usr/bin/python3 /usr/bin/python
RUN pip3 install xdg requests_oauthlib paho-mqtt psutil setproctitle ruamel.yaml
# add ubuntu and testflinger users
RUN useradd -ms /bin/bash ubuntu
# && useradd -ms /bin/bash testflinger
# add to sudoers
RUN echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
# add SSH access
RUN rm -f /etc/service/sshd/down \
&& /etc/my_init.d/00_regen_ssh_host_keys.sh > /dev/null 2>&1
# prepare ssh key ops
COPY ./ssh/authorized_keys /tmp/authorized_keys
COPY ./code/export_ssh_pubkey.py /opt/export_ssh_pubkey.py
# gen ssh keys, update pubkey, import auth_keys, export pubkey into maas
USER ubuntu
# generate ssh key and insert real hostname into pubkey
RUN ssh-keygen -t rsa -N '' -f /home/ubuntu/.ssh/id_rsa \
&& sed -i 's|@buildkitsandbox|@testflinger-cli|gI' /home/ubuntu/.ssh/id_rsa.pub
# import auth_keys
RUN cat /tmp/authorized_keys >> /home/ubuntu/.ssh/authorized_keys
# root must be last
USER root
RUN ssh-keygen -t rsa -N '' -f /root/.ssh/id_rsa \
&& sed -i 's|@buildkitsandbox|@testflinger-cli|gI' /root/.ssh/id_rsa.pub
RUN cat /tmp/authorized_keys >> /root/.ssh/authorized_keys \
&& rm -f /tmp/authorized_keys
# facilitate logging
RUN mkdir -p /var/log/testflinger \
&& chmod 755 /var/log/testflinger
# facilitate submit-agent logging
RUN mkdir /var/log/submit-agent \
&& chown ubuntu:ubuntu /var/log/submit-agent
# clone src in volume dir
WORKDIR /data/testflinger-cli
RUN git init \
&& git remote add origin https://github.com/canonical/testflinger-cli.git \
&& git fetch origin \
&& git checkout -b main --track origin/main
# copy sut files
RUN mkdir /data/testflinger-cli/sut/
COPY ./sut/cli/* /data/testflinger-cli/sut/
# USER ubuntu
RUN python3 setup.py install
# adjust perms on src files
RUN chown -R ubuntu:ubuntu /data/testflinger-cli
# copy entrypoint
COPY ./code/tf-entrypoint.sh /opt/tf-entrypoint.sh
RUN chmod 755 /opt/tf-entrypoint.sh
# copy submission agent file
COPY ./code/start_submit_agents.py /opt/start_submit_agents.py
RUN chmod 755 /opt/start_submit_agents.py
# copy agent service file
COPY code/01_run_submit_agents.sh /etc/my_init.d/01_run_submit_agents.sh
# copy refernce yaml file
USER ubuntu
COPY code/reference.yaml /data/testflinger-cli/sut/.reference.yaml
# set user passwords (temp pw)
USER root
RUN echo "ubuntu:${ubuntu_scr}" | chpasswd
# RUN echo "testflinger:${testflinger_scr}" | chpasswd
# set user passwords (secure method)
# RUN --mount=type=secret,id=tf_secret,required=true chpasswd < /run/secrets/tf_secret