forked from canonical/testflinger-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tf-agent
178 lines (147 loc) · 5.04 KB
/
tf-agent
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
FROM phusion/baseimage:focal-1.0.0
ARG ubuntu_scr
ARG host_dir
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-agent:/data/snappy-device-agents:$PATH
ENV HOSTDIR ${host_dir}
# add maas-cli PPA
RUN apt-add-repository ppa:maas/2.9 -y
# add docker
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
# install deps & cleanup
RUN apt-get update \
&& apt-cache policy docker-ce \
&& apt-get install -y \
--no-install-recommends \
ca-certificates \
gpg \
lsb-release \
docker-ce \
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
# uuid-dev \
# zlib1g-dev \
# libjson-c-dev \
# gcc \
# make \
# automake \
# autotools-dev \
# autoconf \
# pkg-config
# 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 requests_oauthlib psutil setproctitle paho-mqtt docker
# add ubuntu user
RUN useradd -ms /bin/bash ubuntu \
&& usermod -aG docker ubuntu
# 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
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-agent|gI' /home/ubuntu/.ssh/id_rsa.pub
# import auth_keys
RUN cat /tmp/authorized_keys >> /home/ubuntu/.ssh/authorized_keys
# USER testflinger
# RUN ssh-keygen -t rsa -N '' -f /home/testflinger/.ssh/id_rsa \
# && sed -i 's|@buildkitsandbox|@testflinger-agent|gI' /home/testflinger/.ssh/id_rsa.pub
# RUN cat /tmp/authorized_keys >> /home/testflinger/.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-agent|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 sut-agent logging
RUN mkdir /var/log/sut-agent \
&& chown ubuntu:ubuntu /var/log/sut-agent
# clone tf-agent src in volume dir
WORKDIR /data/testflinger-agent
RUN git init \
&& git remote add origin https://github.com/canonical/testflinger-agent.git \
&& git fetch origin \
&& git checkout -b main --track origin/main
# copy tf-agent config files
COPY ./code/testflinger-agent.conf /data/testflinger-agent
# copy tf-agent sut files
RUN mkdir ./sut/
COPY ./sut/agent/* /data/testflinger-agent/sut/
# clone snappy-agent src in volume dir
WORKDIR /data/snappy-device-agents
RUN git init \
&& git remote add origin https://github.com/canonical/snappy-device-agents.git \
&& git fetch origin \
&& git checkout -b main --track origin/main
# copy snappy-agent sut files
RUN mkdir ./sut/
COPY ./sut/snappy/* /data/snappy-device-agents/sut/
# run tf-agent setup
# USER ubuntu
WORKDIR /data/testflinger-agent
RUN echo && echo "Running testflinger-agent setup:" \
&& python3 setup.py install
#run snappy-agent setup
WORKDIR /data/snappy-device-agents
RUN echo && echo "Running snappy-device-agents setup:" \
&& python3 setup.py install
# adjust perms on src files
RUN chown -R ubuntu:ubuntu /data/testflinger-agent \
&& chmod 775 /data/testflinger-agent \
&& chown -R ubuntu:ubuntu /data/snappy-device-agents \
&& chmod 775 /data/snappy-device-agents
# # netdata
# RUN git clone https://github.com/netdata/netdata.git --depth=100 --recursive
# RUN ./netdata/netdata-installer.sh --dont-start-it --disable-telemetry
# RUN chown -R root:root /var/log/netdata
# copy entrypoint file
COPY ./code/tf-entrypoint.sh /opt/tf-entrypoint.sh
RUN chmod 755 /opt/tf-entrypoint.sh
# copy agent service files
COPY ./code/01_run_sut_agents.sh /etc/my_init.d/01_run_sut_agents.sh
RUN chmod 755 /etc/my_init.d/*
# COPY code/04_netdata.sh /etc/my_init.d/02_netdata.sh
# copy cntnr rscrcs
RUN mkdir /data/docker
COPY ./code/init_agent_cntnrs.py /opt/init_agent_cntnrs.py
COPY ./tf-agent_cntnr /data/docker/Dockerfile
COPY ./ssh/authorized_keys /data/docker/authorized_keys
# docker auth
RUN docker login -u alanec -p 32aafe13-c040-4a93-a0e2-848f5468b4c1
# set user passwords (temp pw)
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