Skip to content

Commit abbb90e

Browse files
Dev khadkaDev khadka
authored andcommitted
Testing for creating configurable docker file for development and production environment
1 parent 985bacf commit abbb90e

File tree

8 files changed

+148
-45
lines changed

8 files changed

+148
-45
lines changed

Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,19 @@ ENV APACHE_LOCK_DIR /var/lock/apache2
3535

3636
ADD entrypoint.sh /root/entrypoint.sh
3737
RUN chmod 777 /root/entrypoint.sh
38-
ENTRYPOINT /root/entrypoint.sh
3938

39+
ARG BUILD_TYPE=PROD
40+
ARG PROJECT_DIR=project
4041

42+
ENV BUILD_TYPE $BUILD_TYPE
43+
44+
45+
#RUN if [ $BUILD_TYPE="PROD" ]; then echo "project.conf"; LARAVEL_PROJECT_DIR="project.conf"; else echo "project"; LARAVEL_PROJECT_DIR="project"; fi
46+
47+
RUN echo $PROJECT_DIR
48+
49+
ADD $PROJECT_DIR /var/www/html/project
50+
51+
ENTRYPOINT [ "/bin/bash", "/root/entrypoint.sh", "entrypoint" ]
4152

4253
EXPOSE 80

docker-compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
- webnet
1616
web:
1717
# replace username/repo:tag with your name and image details
18-
image: laravelapache
18+
image: laravelapache-dev
1919
deploy:
2020
replicas: 1
2121
#restart_policy:
@@ -25,7 +25,7 @@ services:
2525
cpus: "0.5"
2626
memory: 2048M
2727
volumes:
28-
- "/Volumes/Projects/Docker/LaravelApache/project:/var/www/html/project"
28+
- "${PWD}/project:/var/www/html/project"
2929
ports:
3030
- "80:80"
3131
- "2222:22"

dockerbuild.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
3+
#This script calls the "docker build" command for development or production environment base on parameter passed
4+
#For development environment it sends build argument "PROJECT_DIR=project" which will be mapped as application directory in container. Any changes in project directory is reflected in container without doing docker build again.
5+
#For production environment we want project directory to be included in docker image file so we send "PROJECT_DIR=project.conf" where project.conf is a random file
6+
7+
#Rather then sending build argument to docker build file it may be better to change docker file it self with this script. Also we need to change docker-compose.yaml not to map project folder as volume.
8+
9+
10+
dev_build_args=("BUILD_TYPE=dev"
11+
"PROJECT_DIR=project");
12+
prod_build_args=("BUILD_TYPE=prod"
13+
"PROJECT_DIR=project.conf");
14+
15+
while getopts 't:e:' opt; do
16+
case $opt in
17+
t) tag="$OPTARG" ;;
18+
e) eenv="$OPTARG";;
19+
*) exit 1 ;;
20+
esac
21+
done
22+
23+
24+
if [ -z $tag ] || [ -z $eenv ]; then
25+
echo "Please provide parameters";
26+
echo "-t = docker build tag";
27+
echo "-e = env, either 'dev' or 'prod'";
28+
exit 1;
29+
else
30+
echo "parameters are good";
31+
fi
32+
33+
if [ "dev" == $eenv ]; then
34+
build_args=(${dev_build_args[@]});
35+
elif [ "prod" == $eenv ]; then
36+
build_args=(${prod_build_args[@]})
37+
else
38+
echo "Please give valid option, either 'prod' or 'dev'";
39+
exit 1;
40+
fi
41+
42+
43+
cmd="docker build -t $tag ";
44+
45+
echo ${dev_build_args[@]};
46+
for arg in "${build_args[@]}";
47+
do
48+
cmd+="--build-arg \"$arg\" ";
49+
echo $arg;
50+
done
51+
52+
cmd+="."
53+
54+
echo "Running: " $cmd;
55+
56+
57+
eval $cmd;
58+
59+
60+
61+

dockerdeploy.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
if [ $1=="dev" ]; then
3+
4+
elif [ $1=="prod" ];
5+
6+
else
7+
echo "Please give valid option, either 'prod' or 'dev'";
8+
fi;

entrypoint.sh

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,50 @@
1+
#!/bin/bash
12
# Don't remove, this command is needed to start ssh server when docker is started
23
/usr/sbin/sshd;
34

4-
cd /var/www/html/project;
5-
# Creates laravel project if doesn't exists already
6-
if [ -f composer.json ]; then
7-
echo "Laravel project exists";
8-
if [ -d vendor ]; then
9-
echo "Vendor folder exists not installing composer packages.";
10-
else
11-
echo "Install composer packages";
12-
composer install -vv;
13-
fi
14-
else
15-
echo "Laravel project doesn't exist, creating new ...";
16-
composer -vvv create-project laravel/laravel /var/www/html/project --prefer-dist;
17-
fi
18-
19-
20-
php artisan migrate;
21-
22-
# Install Node dependencies from package.json file if exists
23-
if [ -f /var/www/html/project/package.json ]; then
24-
if [ -d /var/www/html/project/node_modules ]; then
25-
echo "Node modules already installed";
26-
else
27-
echo "Install node modules";
28-
npm --prefix /var/www/html/project install /var/www/html/project;
29-
fi
30-
else
31-
echo "No package.json file";
32-
fi
5+
6+
echo $BUILD_TYPE;
7+
echo $1;
8+
9+
# cd /var/www/html/project;
10+
# # Creates laravel project if doesn't exists already
11+
# if [ -f composer.json ]; then
12+
# echo "Laravel project exists";
13+
# if [ -d vendor ]; then
14+
# echo "Vendor folder exists not installing composer packages.";
15+
# else
16+
# echo "Install composer packages";
17+
# composer install -vv;
18+
# fi
19+
# else
20+
# echo "Laravel project doesn't exist, creating new ...";
21+
# composer -vvv create-project laravel/laravel /var/www/html/project --prefer-dist;
22+
# fi
23+
24+
25+
# # Install Node dependencies from package.json file if exists
26+
# if [ -f package.json ]; then
27+
# if [ -d node_modules ]; then
28+
# echo "Node modules already installed";
29+
# else
30+
# echo "Install node modules";
31+
# npm install;
32+
# fi
33+
# else
34+
# echo "No package.json file";
35+
# fi
3336

3437

3538
# make following folders accessible to apache
3639
chgrp -R www-data /var/www/html/project/storage;
3740
chgrp -R www-data /var/www/html/project/bootstrap/cache;
3841
chmod -R 777 /var/www/html/project/storage;
3942

40-
echo "Apache server is running ..., browser your project using 'localhost' ";
43+
# echo "Running migration...";
44+
# php artisan migrate;
45+
46+
47+
echo "Apache server is running ..., browse your project using 'localhost' ";
4148
#Launch apache in the foreground
4249
#We do this in the forground so that Docker can watch
4350
#the process to detect if it has crashed
@@ -46,3 +53,4 @@ apache2 -DFOREGROUND;
4653

4754

4855

56+

id_rsa

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIIEpAIBAAKCAQEAzEh+bqhiC8ghBeDgvE/Y3pfA9CzK64MXodF5GhFSZK0pqXel
3+
jzZzmKT+cFKGeFLgWx3JgHzDURpHbsUjxG144iuUNKIf9jkDC2ZxPIg/UGw3fM64
4+
8rhJscLmPbsq8ceygwRz/2eW5QVwZEbLZubR/G48ry2ArU4EzddTiBKknvlmoWAM
5+
xre0fkPLPUr48hnSK0srOCChTk+RkaNsZK1P+HQnlqJrjs33Y0y7BkUDmjgILUyv
6+
lpTi8YvX6gniccFCG3krywOXmQowSR/H2+IYaD8Kuhz1YIIRbRHvWhk4TkHjtjLH
7+
uF0aELESfLKpgrnVrRJ0gS6mwj+t0aPuz4Zl1QIDAQABAoIBAHrpg2kBVzzPhU8M
8+
Jywmvs3vcOF5sf5SOf3bE4pjsbdxmQemPa8VjCfj3lOm09HBy8wG+B6e8sXxkdlM
9+
NGETnRA4OEwS4Dg9xV8unCNXtwCknB40I4Om7nBOXEn4O7aN+RJrs3+QzHGv/BfZ
10+
oLihWOcRTOH59tpPfwR68n+E+BfN0v5/HOeM6hRtfmU3wNXmt0T6QJHRe0Ecv3Yl
11+
Rc2c8H57Fs1PgtH8NdWcxud7CsNPourgU90jj8x1FKdupWfN8TgchY3tvGrejxYq
12+
gLnwXBIihILXgOtr12UT1B4FYH8bjGsphzWCOEGQLkXgbnMbdia+SYGICHwb/sek
13+
eXhOC2ECgYEA/jbQKZsO74qXA7tj/FXoxjZ6GrblZsLIzqFErNDgy/8eRRyURD9i
14+
co64pywp00DYz6FnwrryaSdU8BMEiMM9futzm94rnedeXjTOquFebkR2piRsc8Nu
15+
pHnA//MjnAD8klP16s1SO8smai7nar6mrvlmfgfKppYkhXWB8SSdVLsCgYEAzbfi
16+
ImMd4LrOXVRdeAdkvi6PsOnR+GlnSJt5Nfnj5lJH+6nz31CsO/NBrOJaBMjDKQA2
17+
lETdIhE7uoVn2CjblQccEPlW1+5DT0UgtvHIIZRxxRoNWJ2rEJl+ycmUPMJ3rKV1
18+
TbuP8ljOv6LtjDvUju0V9zPWGCP5iQs+tIIxzq8CgYEAxse5si7rWOf3+hUXtALB
19+
R+zlQepuKxJ4zwpPlwqmHR3aX5RfY5ZktstfHGluMyBr6L9/UUe5sfvtcOSOERsK
20+
BSq7ddAeLxTyN5v3Vqtvma2zUWr92u+gnsAN6JYI7D3hQdKhYv82JEdQPIt8rX1y
21+
/TNLr5UMI4MX/7vI5fUJiW0CgYBCf7uQxBuHZruIvdnNEA7Hz4NRe/QM6f2iIefn
22+
w9Sgwl5Ugta7jHdwlazYNv9EZqV3noMGINCez5VQMQmlfWel3/t5nTAucu29NSpj
23+
GPtJp5OzVD2WNLl0jznF/ux1S6Ol4oJt00Cv5XdHyWIin8CRRyB/nXkKqq5iV4k4
24+
jpGNLwKBgQCXPuHocYt2TQy5KGyT2wEtFcK1HyGj1SUcXBCtgRAGTo1mVCzFGT52
25+
RuXdLLgQsNshWTmjcM+36DTowPrKklnl97TBVbbQraDJta9msRuWPLOpV3E8ablJ
26+
DBDo9iQ6YjwUd7q2VNIKAeGDAOIy5UnMJFZzTh8uTjhvQnJXQdQG1w==
27+
-----END RSA PRIVATE KEY-----

project/.gitignore

Lines changed: 0 additions & 12 deletions
This file was deleted.

test.sh

Whitespace-only changes.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy