Skip to content

Commit ad73074

Browse files
authored
Merge pull request #1 from cytopia/DAP-001
DAP-001 Enhancing automated builds
2 parents cdfc7f8 + 0f241e4 commit ad73074

15 files changed

+416
-178
lines changed

.gitignore

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Note:
2+
# To effectively apply the changes you will have
3+
# to re-index the git index (if there are already
4+
# commited files)
5+
#
6+
# $ git rm -r --cached .
7+
# $ git add .
8+
# $ git commit -m ".gitignore index rebuild"
9+
#
10+
11+
12+
######################################
13+
# CUSTOM
14+
######################################
15+
16+
17+
######################################
18+
# GENERIC
19+
######################################
20+
21+
###### std ######
22+
.lock
23+
*.log
24+
25+
###### patches/diffs ######
26+
*.patch
27+
*.diff
28+
*.orig
29+
*.rej
30+
31+
32+
######################################
33+
# Operating Systems
34+
######################################
35+
36+
###### OSX ######
37+
._*
38+
.DS*
39+
.Spotlight-V100
40+
.Trashes
41+
42+
###### Windows ######
43+
Thumbs.db
44+
ehthumbs.db
45+
Desktop.ini
46+
$RECYCLE.BIN/
47+
*.lnk
48+
*.shortcut
49+
50+
######################################
51+
# Editors
52+
######################################
53+
54+
###### Sublime ######
55+
*.sublime-workspace
56+
*.sublime-project
57+
58+
###### Eclipse ######
59+
.classpath
60+
.buildpath
61+
.project
62+
.settings/
63+
64+
###### Netbeans ######
65+
/nbproject/
66+
67+
###### Intellij IDE ######
68+
.idea/
69+
.idea_modules/
70+
71+
###### vim ######
72+
*.swp
73+
*.swo
74+
*.swn
75+
*.swm
76+
*~
77+
78+
###### TextMate ######
79+
.tm_properties
80+
*.tmproj
81+
82+
###### BBEdit ######
83+
*.bbprojectd
84+
*.bbproject
85+
86+
.vagrant

.travis.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ install:
4646
- echo "<?php error_reporting(-1); ini_set('display_errors', 1); if (mysqli_connect(gethostbyname('mysql'), 'root', '')) { echo 'YES'; } else { echo 'NO ' . mysqli_connect_error(); }" > ~/www/mysql_ip.php
4747

4848

49+
###
50+
### Disable auto-started daemons
51+
###
52+
before_script:
53+
54+
# Disable services enabled by default
55+
# http://docs.travis-ci.com/user/database-setup/#MySQL
56+
- sudo /etc/init.d/mysql stop
57+
- sudo /etc/init.d/postgresql stop
58+
4959

5060
###
5161
### Test
@@ -85,7 +95,6 @@ script:
8595
- docker rm "${MY_DOCKER_NAME}"
8696

8797

88-
8998
##
9099
## 02.) [a](DEBUG) Test docker with external mounted directory
91100
##
@@ -127,7 +136,6 @@ script:
127136
- docker rm "${MY_DOCKER_NAME}"
128137

129138

130-
131139
##
132140
## 03.) [a](DEBUG) Test docker with external mounted directory and PHP-FPM support
133141
##
@@ -194,7 +202,6 @@ script:
194202
- docker rm "${MY_DOCKER_NAME}"
195203

196204

197-
198205
##
199206
## 04.) [a](DEBUG) Test docker with external mounted directory and PHP-FPM support and MySQL support
200207
##

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LABEL \
1313
image="nginx-mainline" \
1414
vendor="cytopia" \
1515
license="MIT" \
16-
build-date="2016-11-03"
16+
build-date="2017-04-18"
1717

1818

1919
# Copy scripts

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Nginx mainline Docker
22

3+
<small>**Latest build:** 2017-04-18</small>
4+
35
[![Build Status](https://travis-ci.org/cytopia/docker-nginx-mainline.svg?branch=master)](https://travis-ci.org/cytopia/docker-nginx-mainline) [![](https://images.microbadger.com/badges/version/cytopia/nginx-mainline.svg)](https://microbadger.com/images/cytopia/nginx-mainline "nginx-mainline") [![](https://images.microbadger.com/badges/image/cytopia/nginx-mainline.svg)](https://microbadger.com/images/cytopia/nginx-mainline "nginx-mainline") [![](https://images.microbadger.com/badges/license/cytopia/nginx-mainline.svg)](https://microbadger.com/images/cytopia/nginx-mainline "nginx-mainline")
46

57
[![cytopia/nginx-mainline](http://dockeri.co/image/cytopia/nginx-mainline)](https://hub.docker.com/r/cytopia/nginx-mainline/)
@@ -142,3 +144,12 @@ It allows any of the following combinations:
142144
* MySQL 5.5, MySQL 5.6, MySQL 5.7, MariaDB 5 and MariaDB 10
143145
* Apache 2.2, Apache 2.4, Nginx stable and Nginx mainline
144146
* And more to come...
147+
148+
## Version
149+
150+
```
151+
nginx version: nginx/1.11.13
152+
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)
153+
built with OpenSSL 1.0.1e-fips 11 Feb 2013
154+
TLS SNI support enabled
155+
```

build/docker-attach.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/sh -eu
2+
3+
4+
###
5+
### Globals
6+
###
7+
CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)/.."
8+
9+
10+
###
11+
### Funcs
12+
###
13+
run() {
14+
_cmd="${1}"
15+
_red="\033[0;31m"
16+
_green="\033[0;32m"
17+
_reset="\033[0m"
18+
_user="$(whoami)"
19+
20+
printf "${_red}%s \$ ${_green}${_cmd}${_reset}\n" "${_user}"
21+
sh -c "LANG=C LC_ALL=C ${_cmd}"
22+
}
23+
24+
25+
###
26+
### Checks
27+
###
28+
29+
# Check Dockerfile
30+
if [ ! -f "${CWD}/Dockerfile" ]; then
31+
echo "Dockerfile not found in: ${CWD}/Dockerfile."
32+
exit 1
33+
fi
34+
35+
# Get docker Name
36+
if ! grep -q 'image=".*"' "${CWD}/Dockerfile" > /dev/null 2>&1; then
37+
echo "No 'image' LABEL found"
38+
exit
39+
fi
40+
41+
# Make sure exactly 1 container is running
42+
NAME="$( grep 'image=".*"' "${CWD}/Dockerfile" | sed 's/^[[:space:]]*//g' | awk -F'"' '{print $2}' )"
43+
COUNT="$( docker ps | grep -c "cytopia/${NAME}" || true)"
44+
if [ "${COUNT}" != "1" ]; then
45+
echo "${COUNT} 'cytopia/${NAME}' container running. Unable to attach."
46+
exit 1
47+
fi
48+
49+
50+
###
51+
### Attach
52+
###
53+
DID="$(docker ps | grep "cytopia/${NAME}" | awk '{print $1}')"
54+
55+
echo "Attaching to: cytopia/${NAME}"
56+
run "docker exec -it ${DID} env TERM=xterm /bin/bash -l"

build/docker-build.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/sh -eu
2+
3+
4+
###
5+
### Globals
6+
###
7+
CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)/.."
8+
9+
10+
###
11+
### Funcs
12+
###
13+
run() {
14+
_cmd="${1}"
15+
_red="\033[0;31m"
16+
_green="\033[0;32m"
17+
_reset="\033[0m"
18+
_user="$(whoami)"
19+
20+
printf "${_red}%s \$ ${_green}${_cmd}${_reset}\n" "${_user}"
21+
sh -c "LANG=C LC_ALL=C ${_cmd}"
22+
}
23+
24+
25+
###
26+
### Checks
27+
###
28+
29+
# Check Dockerfile
30+
if [ ! -f "${CWD}/Dockerfile" ]; then
31+
echo "Dockerfile not found in: ${CWD}/Dockerfile."
32+
exit 1
33+
fi
34+
35+
# Get docker Name
36+
if ! grep -q 'image=".*"' "${CWD}/Dockerfile" > /dev/null 2>&1; then
37+
echo "No 'image' LABEL found"
38+
exit
39+
fi
40+
NAME="$( grep 'image=".*"' "${CWD}/Dockerfile" | sed 's/^[[:space:]]*//g' | awk -F'"' '{print $2}' )"
41+
DATE="$( date '+%Y-%m-%d' )"
42+
43+
44+
###
45+
### Build
46+
###
47+
48+
# Update build date
49+
run "sed -i'' 's/<small>\*\*Latest\sbuild.*/<small>**Latest build:** ${DATE}<\/small>/g' ${CWD}/README.md"
50+
run "sed -i'' 's/build-date=\".*\"/build-date=\"${DATE}\"/g' ${CWD}/Dockerfile"
51+
52+
# Build Docker
53+
run "docker build -t cytopia/${NAME} ${CWD}"
54+
55+
56+
###
57+
### Retrieve information afterwards and Update README.md
58+
###
59+
docker run -d --name my_tmp_${NAME} -t cytopia/${NAME}
60+
INFO="$( docker exec my_tmp_${NAME} nginx -V 2>&1 | grep -E '^(nginx|built|TLS)' )"
61+
docker stop "$(docker ps | grep "my_tmp_${NAME}" | awk '{print $1}')"
62+
docker rm "my_tmp_${NAME}"
63+
64+
INFO="$( echo "${INFO}" | sed 's/\s$//g' )" # remove trailing space
65+
echo "${INFO}"
66+
67+
sed -i'' '/##[[:space:]]Version/q' "${CWD}/README.md"
68+
echo "" >> "${CWD}/README.md"
69+
echo '```' >> "${CWD}/README.md"
70+
echo "${INFO}" >> "${CWD}/README.md"
71+
echo '```' >> "${CWD}/README.md"

build/docker-enter.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/sh -eu
2+
3+
4+
###
5+
### Globals
6+
###
7+
CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)/.."
8+
9+
10+
###
11+
### Funcs
12+
###
13+
run() {
14+
_cmd="${1}"
15+
_red="\033[0;31m"
16+
_green="\033[0;32m"
17+
_reset="\033[0m"
18+
_user="$(whoami)"
19+
20+
printf "${_red}%s \$ ${_green}${_cmd}${_reset}\n" "${_user}"
21+
sh -c "LANG=C LC_ALL=C ${_cmd}"
22+
}
23+
24+
25+
###
26+
### Checks
27+
###
28+
29+
# Check Dockerfile
30+
if [ ! -f "${CWD}/Dockerfile" ]; then
31+
echo "Dockerfile not found in: ${CWD}/Dockerfile."
32+
exit 1
33+
fi
34+
35+
# Get docker Name
36+
if ! grep -q 'image=".*"' "${CWD}/Dockerfile" > /dev/null 2>&1; then
37+
echo "No 'image' LABEL found"
38+
exit
39+
fi
40+
NAME="$( grep 'image=".*"' "${CWD}/Dockerfile" | sed 's/^[[:space:]]*//g' | awk -F'"' '{print $2}' )"
41+
42+
43+
###
44+
### Enter
45+
###
46+
run "docker run -i --entrypoint /bin/bash -t cytopia/${NAME}"

docker-push.sh renamed to build/docker-push.sh

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,43 @@
11
#!/bin/sh -eu
22

3+
4+
###
5+
### Globals
6+
###
7+
CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)/.."
8+
9+
10+
###
11+
### Checks
12+
###
13+
314
# Check Dockerfile
4-
if [ ! -f "Dockerfile" ]; then
5-
echo "Dockerfile not found."
15+
if [ ! -f "${CWD}/Dockerfile" ]; then
16+
echo "Dockerfile not found in: ${CWD}/Dockerfile."
617
exit 1
718
fi
819

920
# Get docker Name
10-
if ! grep -q 'image=".*"' Dockerfile > /dev/null 2>&1; then
21+
if ! grep -q 'image=".*"' "${CWD}/Dockerfile" > /dev/null 2>&1; then
1122
echo "No 'image' LABEL found"
1223
exit
1324
fi
14-
NAME="$( grep 'image=".*"' Dockerfile | sed 's/^[[:space:]]*//g' | awk -F'"' '{print $2}' )"
15-
25+
NAME="$( grep 'image=".*"' "${CWD}/Dockerfile" | sed 's/^[[:space:]]*//g' | awk -F'"' '{print $2}' )"
1626

1727

28+
###
29+
### Docker hub variables
30+
###
1831
USR="cytopia"
1932
IMG="${USR}/${NAME}"
2033
REG="https://index.docker.io/v1/"
2134

2235

23-
2436
##
2537
## Functions
2638
##
2739
get_docker_id() {
28-
_did="$( docker images | grep "${IMG}" | grep "latest" | awk '{print $3}' )"
40+
_did="$( docker images | grep "${IMG}\s" | grep "latest" | awk '{print $3}' )"
2941
echo "${_did}"
3042
}
3143
is_logged_in() {
@@ -41,7 +53,6 @@ is_logged_in() {
4153
}
4254
run() {
4355
_cmd="${1}"
44-
4556
_red="\033[0;31m"
4657
_green="\033[0;32m"
4758
_reset="\033[0m"
@@ -62,4 +73,3 @@ if ! is_logged_in; then
6273
run "docker login"
6374
fi
6475
run "docker push ${IMG}"
65-

0 commit comments

Comments
 (0)