Skip to content

Commit ef8e20f

Browse files
colin-campbellsnipe
authored andcommitted
Alpine linux docker image (#6645)
* docker-alpine: Alpine linux container + apache 2.4 support * docker-alpine: Force passport migrations (production mode Exception) * docker-alpine: Copy default env in Dockerfile
1 parent 9d21fc8 commit ef8e20f

File tree

5 files changed

+156
-1
lines changed

5 files changed

+156
-1
lines changed

.dockerignore

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
.git
2+
.github
3+
.gitattributes
4+
.gitignore
25
.dockerignore
36
app/storage/logs/*
47
app/storage/views/*
58
vendor/*
9+
storage/framework/cache/*
10+
node_modules
11+
.vagrant
12+
.idea
13+

Dockerfile.alpine

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
FROM alpine:3.8
2+
# Apache + PHP
3+
RUN apk add --update --no-cache \
4+
apache2 \
5+
php7 \
6+
php7-common \
7+
php7-apache2 \
8+
php7-curl \
9+
php7-ldap \
10+
php7-mysqli \
11+
php7-gd \
12+
php7-xml \
13+
php7-mbstring \
14+
php7-zip \
15+
php7-ctype \
16+
php7-tokenizer \
17+
php7-pdo_mysql \
18+
php7-openssl \
19+
php7-bcmath \
20+
php7-phar \
21+
php7-json \
22+
php7-iconv \
23+
php7-fileinfo \
24+
php7-simplexml \
25+
php7-session \
26+
curl \
27+
wget \
28+
vim \
29+
git \
30+
mysql-client \
31+
tini
32+
33+
# Where apache's PID lives
34+
RUN mkdir -p /run/apache2 && chown apache:apache /run/apache2
35+
36+
RUN sed -i 's/variables_order = .*/variables_order = "EGPCS"/' /etc/php7/php.ini
37+
COPY docker/000-default-2.4.conf /etc/apache2/conf.d/default.conf
38+
39+
# Enable mod_rewrite
40+
RUN sed -i '/LoadModule rewrite_module/s/^#//g' /etc/apache2/httpd.conf
41+
42+
COPY . /var/www/html
43+
44+
WORKDIR /var/www/html
45+
46+
COPY docker/docker.env /var/www/html/.env
47+
48+
RUN chown -R apache:apache /var/www/html
49+
50+
RUN \
51+
rm -r "/var/www/html/storage/private_uploads" \
52+
&& mkdir -p "/var/lib/snipeit/data/private_uploads" && ln -fs "/var/lib/snipeit/data/private_uploads" "/var/www/html/storage/private_uploads" \
53+
&& rm -rf "/var/www/html/public/uploads" \
54+
&& mkdir -p "/var/lib/snipeit/data/uploads" && ln -fs "/var/lib/snipeit/data/uploads" "/var/www/html/public/uploads" \
55+
&& mkdir -p "/var/lib/snipeit/dumps" && rm -r "/var/www/html/storage/app/backups" && ln -fs "/var/lib/snipeit/dumps" "/var/www/html/storage/app/backups" \
56+
&& mkdir -p "/var/lib/snipeit/keys" && ln -fs "/var/lib/snipeit/keys/oauth-private.key" "/var/www/html/storage/oauth-private.key" \
57+
&& ln -fs "/var/lib/snipeit/keys/oauth-public.key" "/var/www/html/storage/oauth-public.key" \
58+
&& chown -R apache "/var/lib/snipeit"
59+
60+
# Install composer
61+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
62+
RUN mkdir -p /var/www/.composer && chown apache /var/www/.composer
63+
64+
# Install dependencies
65+
USER apache
66+
RUN COMPOSER_CACHE_DIR=/dev/null composer install --no-dev --working-dir=/var/www/html
67+
68+
USER root
69+
70+
VOLUME ["/var/lib/snipeit"]
71+
72+
# Entrypoints
73+
COPY docker/entrypoint_alpine.sh /entrypoint.sh
74+
RUN chmod +x /entrypoint.sh
75+
76+
ENTRYPOINT ["/sbin/tini", "--"]
77+
78+
CMD ["/entrypoint.sh"]
79+
80+
EXPOSE 80

app/Http/Controllers/SettingsController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public function getSetupMigrate()
246246
Artisan::call('migrate', ['--force' => true]);
247247

248248
if ((! file_exists(storage_path() . '/oauth-private.key')) || (! file_exists(storage_path() . '/oauth-public.key'))) {
249-
Artisan::call('migrate', ['--path' => 'vendor/laravel/passport/database/migrations']);
249+
Artisan::call('migrate', ['--path' => 'vendor/laravel/passport/database/migrations', '--force' => true]);
250250
Artisan::call('passport:install');
251251
}
252252

docker/000-default-2.4.conf

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<VirtualHost *:80>
2+
ServerAdmin webmaster@localhost
3+
4+
DocumentRoot "/var/www/html/public"
5+
DirectoryIndex index.php index.html
6+
<Directory "/var/www/html/public">
7+
Options All +MultiViews -ExecCGI -Indexes
8+
<IfModule mod_dav.c>
9+
DAV Off
10+
</IfModule>
11+
AllowOverride All
12+
Require all granted
13+
</Directory>
14+
LogLevel warn
15+
ErrorLog ${APACHE_LOG_DIR}/error.log
16+
CustomLog ${APACHE_LOG_DIR}/access.log combined
17+
</VirtualHost>
18+
19+
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

docker/entrypoint_alpine.sh

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/sh
2+
3+
# fix key if needed
4+
if [ -z "$APP_KEY" ]
5+
then
6+
echo "Please re-run this container with an environment variable \$APP_KEY"
7+
echo "An example APP_KEY you could use is: "
8+
php artisan key:generate --show
9+
exit
10+
fi
11+
12+
#if [ ! -f /var/lib/snipeit/ssl/snipeit-ssl.crt -o ! -f /var/lib/snipeit/ssl/snipeit-ssl.key ]
13+
#then
14+
# rm /etc/apache2/conf.d/ssl.conf && rm /etc/apache2/conf.d/default-ssl.conf
15+
#fi
16+
17+
# create data directories
18+
for dir in \
19+
'data/private_uploads' \
20+
'data/uploads/accessories' \
21+
'data/uploads/avatars' \
22+
'data/uploads/barcodes' \
23+
'data/uploads/categories' \
24+
'data/uploads/companies' \
25+
'data/uploads/components' \
26+
'data/uploads/consumables' \
27+
'data/uploads/departments' \
28+
'data/uploads/locations' \
29+
'data/uploads/manufacturers' \
30+
'data/uploads/models' \
31+
'data/uploads/suppliers' \
32+
'dumps' \
33+
'keys'
34+
do
35+
[ ! -d "/var/lib/snipeit/$dir" ] && mkdir -p "/var/lib/snipeit/$dir"
36+
done
37+
38+
chown -R apache:root /var/lib/snipeit/data/*
39+
chown -R apache:root /var/lib/snipeit/dumps
40+
chown -R apache:root /var/lib/snipeit/keys
41+
42+
# If the Oauth DB files are not present copy the vendor files over to the db migrations
43+
if [ ! -f "/var/www/html/database/migrations/*create_oauth*" ]
44+
then
45+
cp -a /var/www/html/vendor/laravel/passport/database/migrations/* /var/www/html/database/migrations/
46+
fi
47+
export APACHE_LOG_DIR=/var/log/apache2
48+
exec httpd -DNO_DETACH < /dev/null

0 commit comments

Comments
 (0)