Skip to content
This repository was archived by the owner on Aug 4, 2020. It is now read-only.

Commit e541e22

Browse files
committed
support for generatig ssh keys
1 parent 4cbe201 commit e541e22

File tree

5 files changed

+65
-7
lines changed

5 files changed

+65
-7
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ RUN apk --no-cache add \
1818
libpng-dev libjpeg-turbo-dev \
1919
wget \
2020
git \
21+
openssh \
2122
nginx \
2223
ca-certificates \
2324
supervisor \
@@ -44,6 +45,8 @@ RUN apk --no-cache add \
4445

4546
#Configure
4647

48+
RUN ssh-keygen -f /root/.ssh/base_id_rsa -t rsa -N ''
49+
4750
COPY ./config-${BUILD_CONFIG}/nginx/host.conf /etc/nginx/sites-available/template.conf
4851
COPY ./config-${BUILD_CONFIG}/nginx/nginx.conf /etc/nginx/nginx.conf
4952

build.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ docker build -t $BUILDNAME \
136136
.
137137

138138
#Build custom images based on the previously built image
139+
140+
if [ ! -z "$CUSTOMIZE" ] && [ ! -d "$PWD/custom/$CUSTOMIZE" ]; then
141+
warning "Folder ${i} can't be built. Folder missing!"
142+
exit 1
143+
fi
144+
139145
if [ -d "$PWD/custom" ]; then
140146

141147
BUILD_DIR=$PWD/custom

custom/example/Dockerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ ARG BUILD_FROM=test
33

44
FROM $BUILD_FROM
55

6+
# Generate image ssh key
7+
# Images with a key pair should not be pushed to public repositories.
8+
RUN rm -rf /root/.ssh/base_id_rsa* \
9+
&& ssh-keygen -f /root/.ssh/id_rsa -t rsa -N ''
10+
611
#Start your customizations here
712

813
#Example
914

10-
#PostregSQL and zip support
15+
#install postgresql and zip support
1116
RUN set -ex \
1217
&& apk --no-cache add postgresql-dev \
1318
&& docker-php-ext-install pdo pdo_pgsql zip
1419

1520
#Expose port 80
16-
EXPOSE 80
21+
EXPOSE 80

init-scripts/container.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
#!/usr/bin/env bash
22

3+
### Remove base image ssh key
4+
if [ -f "/root/.ssh/base_id_rsa" ] ;
5+
then
6+
rm -rf /root/.ssh/base_id_rsa*
7+
fi
8+
9+
### Retrieve public ssh key (id_rsa.pub)
10+
if [ -f "/root/.ssh/id_rsa.pub" ] ;
11+
then
12+
cp /root/.ssh/id_rsa.pub /var/local/id_rsa.pub
13+
chown www-data /var/local/id_rsa.pub
14+
fi
15+
316
### Set web server root folder according to env variable ###
417

518
NGINX_HOST_TPL_FILE=/etc/nginx/sites-available/template.conf
619
NGINX_HOST_CFG_FILE=/etc/nginx/sites-available/active.conf
720

8-
#PHP_VERSION=$(php -v | grep --only-matching --perl-regexp "\\d\.\\d+\.\\d+" | head -n 1)
9-
#PHP_MAJOR_VERSION=${PHP_VERSION:0:3}
10-
1121
if [ -n "$SERVER_ROOT" ] ;
1222
then
1323
echo "Server root set to ${SERVER_ROOT} ..."

init-scripts/welcome.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
exit;
66
}
77

8-
$boxType = ( $e = getenv('PHP_BUILD_CONFIG') ) ? $e : 'default';
8+
$sshPublicKey = ( $k = @file_get_contents('/var/local/id_rsa.pub') ) ? $k : NULL;
9+
$boxType = ( $e = getenv('PHP_BUILD_CONFIG') ) ? $e : 'default';
910

1011
$nginxVersion = str_replace('nginx/', '', $_SERVER['SERVER_SOFTWARE']);
1112
$phpVersion = phpversion();
@@ -34,6 +35,18 @@
3435
box-shadow: 2px 2px 8px rgba(0, 0, 0, .2);
3536
border-radius: 4px;
3637
}
38+
39+
pre{
40+
word-wrap: break-word;
41+
white-space: pre-wrap;
42+
overflow: auto;
43+
padding: 10px;
44+
border: 1px solid #e3e3e3;
45+
border-radius: 5px;
46+
background: #f4f4f4;
47+
height: auto;
48+
box-shadow: inset 0px 0px 11px rgba(0, 0, 0, 0.3);
49+
}
3750
</style>
3851
</head>
3952
<body>
@@ -49,7 +62,28 @@
4962
<p>
5063
<span style="color:green;">&#x25C9;</span>
5164
PHP v<?php echo $phpVersion; ?>
52-
</p>
65+
</p>
66+
67+
<?php if ( $sshPublicKey ): ?>
68+
<h4>SSH Public Key</h4>
69+
70+
<pre><?php echo $sshPublicKey; ?></pre>
71+
<?php else: ?>
72+
<p>
73+
&#x2716; Could not retrieve ssh public key!
74+
If you want to run a customized version with a key pair,
75+
please customize your base image using template
76+
<a href="https://github.com/adrian7/docker-nginx-fpm/blob/master/custom/example/Dockerfile" target="_blank">
77+
here
78+
</a>.
79+
</p>
80+
<p style="color: #E73A38;">
81+
<em>
82+
&#x26A0; Note that, images with a key pair should not be pushed
83+
to public repositories.
84+
</em>
85+
</p>
86+
<?php endif; ?>
5387

5488
<p>&nbsp;</p>
5589
<p style="font-size: .7em; text-align: center;">

0 commit comments

Comments
 (0)