Skip to content

Commit

Permalink
introduced Debian-version and Matrix-Builds
Browse files Browse the repository at this point in the history
  • Loading branch information
bemayr committed May 11, 2017
1 parent f393e09 commit 1f8a07c
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 30 deletions.
76 changes: 58 additions & 18 deletions create-image.ps1
Original file line number Diff line number Diff line change
@@ -1,36 +1,76 @@
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, HelpMessage="Specify the version of the image you want to create. (directories in ./image) [default: 'base']")]
[String]$image,

[Parameter(Mandatory=$true, HelpMessage="Enter the specified node-version (e.g. 6.10.2) from https://nodejs.org/en/download/releases/.")]
[String]$node_version,

[switch]$silent,
[Parameter(HelpMessage="Specify the versions of the image you want to create. (suffixes in ./images; base images are generated by default)")]
[String]$customized_images = "",

[Switch]$silent,

[switch]$publish
[Switch]$publish
)

$tag = $image + "-" + $node_version
$imagename = "softaware/webdev" + ":" + $tag
$imagepath = "./image/" + $image + "/"
$dockerfile = $imagepath + "Dockerfile"
$generatedfile = $imagepath + "Dockerfile.gen"
# ===== CONSTANTS =====
$repositoryname = "softaware/webdev"
$imagepath = "./images/"
$dockerfilerootpath = "$($imagepath)Dockerfile"

function Generate-Image {
param(
[String]$node_version,
[String]$image_type,
[String]$application_type,
[Boolean]$silent,
[Boolean]$publish
)

$template = Get-Content $dockerfile -Raw
$generated = $template.Replace("{{ node_version }}", $node_version)
$generated | Out-File -Encoding UTF8 $generatedfile
$generatedfile = $imagepath + "Dockerfile.gen"

$command = {docker image build (&{If($silent) {"--quiet"}}) --force-rm -f $generatedfile -t $imagename $imagepath}
if (!$silent) {& $command} else {& $command | Out-Null}
$dockerfile = $dockerfilerootpath + "." + $image_type + $(If($application_type) { ".$($application_type)" })
$tag = $image_type + "-" + $node_version + $(If($application_type) { "-$($application_type)" })
$imagename = $repositoryname + ":" + $tag

$template = Get-Content $dockerfile -Raw
$generated = $template.Replace("{{ node_version }}", $node_version)
$generated | Out-File -Encoding UTF8 $generatedfile

$command = {docker image build (&{If($silent) {"--quiet"}}) --force-rm -f $generatedfile -t $imagename $imagepath}
if (!$silent) {& $command} else {& $command | Out-Null}
Remove-Item $generatedfile

"$($imagename) created successfully"
"$($imagename) created successfully"

if ($publish) {
if ($publish) {
Publish-Image $imagename
}
}

function Publish-Image {
param(
[String]$imagename
)
$command = {docker push $imagename}
if (!$silent) {& $command} else {& $command | Out-Null}

"$($imagename) published successfully"
}

function Generate-Images {
param(
[String]$node_version,
[String[]]$image_types,
[String]$application_type,
[Boolean]$silent,
[Boolean]$publish
)
foreach ($image_type in $image_types) {
Generate-Image $node_version $image_type $image $silent $publish
}
}

$images = @("") + ($customized_images.Split(",") | % { $_.Trim() })

Remove-Item $generatedfile
foreach ($image in $images) {
Generate-Images $node_version @("alpine","debian") $image $silent.IsPresent $publish.IsPresent
}
7 changes: 0 additions & 7 deletions image/node/docker-entrypoint.sh

This file was deleted.

6 changes: 3 additions & 3 deletions image/node/Dockerfile → images/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ RUN apk --no-cache add bash
WORKDIR "/usr/src/app"

# prepare start-script
COPY docker-entrypoint.sh /usr/local/bin/
COPY ./files/docker-entrypoint.sh /usr/local/bin/
RUN chmod a+rx /usr/local/bin/docker-entrypoint.sh

# prepare .profile
# prepare shell
RUN sed -i -e "s/bin\/ash/bin\/bash/" /etc/passwd
COPY .bashrc /root/
COPY ./files/.bashrc /root/

# executing the start-script and dropping into a new bash session
ENTRYPOINT ["docker-entrypoint.sh"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# choose version according to Angular-CLI requirements: https://github.com/angular/angular-cli/blob/master/package.json#L32
FROM softaware/webdev:node-{{ node_version }}
FROM softaware/webdev:alpine-{{ node_version }}

# expose Angular CLI port
EXPOSE 4200
20 changes: 20 additions & 0 deletions images/Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# specify the wanted node/npm version-tag as listed in https://hub.docker.com/r/library/node/tags/
FROM node:{{ node_version }}
LABEL maintainer "bernhard.mayr@softaware.at"

# set path in a way, that local npm-modules (e.g. ng-cli) can be called like executables
ENV PATH="./node_modules/.bin:${PATH}"

# set the working-directory
WORKDIR "/usr/src/app"

# prepare start-script
COPY ./files/docker-entrypoint.sh /usr/local/bin/
RUN chmod a+rx /usr/local/bin/docker-entrypoint.sh

# prepare shell
COPY ./files/.bashrc /root/

# executing the start-script and dropping into a new bash session
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["bash"]
5 changes: 5 additions & 0 deletions images/Dockerfile.debian.angular
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# choose version according to Angular-CLI requirements: https://github.com/angular/angular-cli/blob/master/package.json#L32
FROM softaware/webdev:debian-{{ node_version }}

# expose Angular CLI port
EXPOSE 4200
2 changes: 1 addition & 1 deletion image/node/.bashrc → images/files/.bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ fi
# https://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/
export PS1="dev@docker:\e[1;36m[\W]\e[m> "

printf '\nYour Webdevelopment-Environment is ready to go - Start Coding... ;)\n\n'
printf '\nYour Webdevelopment-Environment is ready to go - Start Coding... ;)\n\n'
12 changes: 12 additions & 0 deletions images/files/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

if [ -f package.json ]; then
if [ -d node_modules ]; then
printf "Checking npm packages...\n"
else
printf "Installing npm packages...\n"
fi
npm install --loglevel warn
fi

exec "$@"

0 comments on commit 1f8a07c

Please sign in to comment.