-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker
executable file
·68 lines (53 loc) · 2.12 KB
/
docker
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
#!/bin/bash
# The container name to use.
container_name="laravel-blade-cli"
# Is TTY supported?
test -t 1 && USE_TTY="-t"
# Create a workspace area for temporary files to do build with.
workspace="./.laravel-blade-cli"
mkdir -p $workspace
cd $workspace
cat > Dockerfile <<EOF
FROM php:8.3-cli-alpine
RUN addgroup -g 1000 php && adduser -u 1000 -S php -G php
WORKDIR /app
ARG PHP_EXTS="pcntl"
ARG DEBIAN_FRONTEND=noninteractive
RUN apk --no-cache update \\
&& docker-php-ext-install -j\$(nproc) \${PHP_EXTS} \\
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \\
&& chown -R php:php /app/
USER php
RUN composer require surgiie/laravel-blade-cli
ENV PATH=\$PATH:/app/vendor/bin
EOF
# Create a sha1sum of the Dockerfile to use to suffix the image tag so if any changes to dockerfile are made, a new image is built.
sha1sum=$(sha1sum Dockerfile | awk '{print $1}')
image_tag="laravel-blade-cli:$sha1sum"
# Build docker image for the cli if not already present or allow with a flag to force build.
if [ -z "$(docker images -q $image_tag)" ] || [[ " $@ " =~ "--docker-build" ]]
then
docker build -t $image_tag . --no-cache
if [[ " $@ " =~ "--docker-build" ]]
then
exit 0;
fi
fi
if [ $? -ne 0 ];
then
echo "Failed to build docker image $image_tag"
exit 1
fi
# Change back to the original directory after we have built the docker image.
cd - > /dev/null
# Remove the workspace after we have built the docker image, these files are no longer needed.
rm -rf $workspace
# Start up a container and keep running it if it is not already running.
if [ ! "$( docker container inspect -f '{{.State.Running}}' $container_name 2>/dev/null)" = "true" ];
then
# remove dangling containers that may have exited but still show up during docker ps -a
docker ps -a | grep $container_name > /dev/null && docker rm $container_name > /dev/null
docker run --name $container_name -i ${USE_TTY} -d --user $(id -u):$(id -g) $image_tag tail -f /dev/null > /dev/null
fi
# Then run the command in the container.
docker exec -i ${USE_TTY} $container_name "laravel-blade" "${@}"