Skip to content

Commit

Permalink
Merge pull request #62 from theohbrothers/docs/simplify-readme-and-ad…
Browse files Browse the repository at this point in the history
…d-simpler-examples

Docs: Simplify readme and add simpler examples
  • Loading branch information
leojonathanoh authored Oct 8, 2022
2 parents eee52f1 + 8ef4b73 commit 9258c97
Show file tree
Hide file tree
Showing 72 changed files with 999 additions and 448 deletions.
327 changes: 136 additions & 191 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Files' definition
$FILES = @(
'.gitlab-ci.yml'
'README.md'
)
)
Original file line number Diff line number Diff line change
@@ -1,112 +1,60 @@
# Docker image variants' definitions
$VARIANTS = @(
@{
# Specifies the docker image tag
tag = 'perl'
# Specifies a distro (optional). If you dont define a distro, templates will be sourced from /generate/templates/<file> folder
# In contrast, if a distro is specified, templates will be sourced from /generate/templates/<file>/<distro> folder
distro = 'alpine'
# Specifies an list of components to process. If undefined, the components will be determined from the tag.
# If unspecified, this is automatically populated
# components = @( 'foo' )
}
@{
# Specifies the docker image tag
tag = 'python'
# Specifies a distro (optional). If you dont define a distro, templates will be sourced from /generate/templates/<file> folder
# In contrast, if a distro is specified, templates will be sourced from /generate/templates/<file>/<distro> folder
distro = 'alpine'
# Specifies an list of components to process. If undefined, the components will be determined from the tag.
# If unspecified, this is automatically populated
# components = @( 'foo' )
}
@{
# Specifies the docker image tag
tag = 'git'
# Specifies a distro (optional). If you dont define a distro, templates will be sourced from /generate/templates/<file> folder
# In contrast, if a distro is specified, templates will be sourced from /generate/templates/<file>/<distro> folder
distro = 'alpine'
# Specifies an list of components to process. If undefined, the components will be determined from the tag.
# If unspecified, this is automatically populated
# components = @( 'foo' )
}
@{
# Specifies the docker image tag
tag = 'perl-git'
# Specifies a distro (optional). If you dont define a distro, templates will be sourced from /generate/templates/<file> folder
# In contrast, if a distro is specified, templates will be sourced from /generate/templates/<file>/<distro> folder
distro = 'alpine'
# Specifies an list of components to process. If undefined, the components will be determined from the tag.
# If unspecified, this is automatically populated
# components = @( 'foo' )
}
@{
# Specifies the docker image tag
tag = 'python-git'
# Specifies a distro (optional). If you dont define a distro, templates will be sourced from /generate/templates/<file> folder
# In contrast, if a distro is specified, templates will be sourced from /generate/templates/<file>/<distro> folder
distro = 'alpine'
# Specifies an list of components to process. If undefined, the components will be determined from the tag.
# If unspecified, this is automatically populated
# components = @( 'foo' )
}
@{
# Specifies the docker image tag
tag = 'perl-python-git'
# Specifies a distro (optional). If you dont define a distro, templates will be sourced from /generate/templates/<file> folder
# In contrast, if a distro is specified, templates will be sourced from /generate/templates/<file>/<distro> folder
distro = 'alpine'
# Specifies an list of components to process. If undefined, the components will be determined from the tag.
# If unspecified, this is automatically populated
# components = @( 'foo' )
# Specifies that this variant should be tagged ':latest'. This property will be useful in generation of content in README.md or ci files. Automatically populated as $false if unspecified
tag_as_latest = $true
}
)

# This is a special global that sets a common buildContextFiles definition for all variants
# Docker image variants' definitions (shared)
$VARIANTS_SHARED = @{
buildContextFiles = @{
templates = @{
# The path of the template to process, relative to the templates directory, omitting the '.ps1' extension
'Dockerfile' = @{
# Specifies whether the template is common (shared) across distros
common = $false
# Specifies whether the template <file>.header.ps1 will be processed. Useful for Dockerfiles
includeHeader = $true
# Specifies whether the template <file>.footer.ps1 will be processed. Useful for Dockerfiles
includeFooter = $true
# Specifies a list of passes the template will be undergo, where each pass generates a file
passes = @(
@{
# These variables will be available in $PASS_VARIABLES hashtable when this template is processed
variables = @{
maintainer = 'The Oh Brothers'
}
}
)
}
# The path of the template to process, relative to the templates directory, omitting the '.ps1' extension
'config/config.yml' = @{
# Specifies whether the template is common (shared) across distros
common = $true
# Specifies whether the template <file>.header.ps1 will be processed. Useful for Dockerfiles
includeHeader = $false
# Specifies whether the template <file>.footer.ps1 will be processed. Useful for Dockerfiles
includeFooter = $false
# Specifies a list of passes the template will be undergo, where each pass generates a file
passes = @(
@{
# These variables will be available in $PASS_VARIABLES hashtable when this template is processed
variables = @{
foo = 'bar'
}
}
)
}
}
# Specifies the paths, relative to the root of the repository, to recursively copy into each variant's build context
copies = @(
'/app'
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Files' definition
$FILES = @(
'.gitlab-ci.yml'
'README.md'
)
)
Original file line number Diff line number Diff line change
@@ -1,36 +1,16 @@
# Docker image variants' definitions
$VARIANTS = @(
@{
# Specifies the docker image tag
tag = 'curl-git'
# Specifies a distro (optional). If you dont define a distro, templates will be sourced from /generate/templates/<file> folder
# In contrast, if a distro is specified, templates will be sourced from /generate/templates/<file>/<distro> folder
distro = ''
# Specifies an list of components to process. If undefined, the components will be determined from the tag.
# If unspecified, this is automatically populated
# components = @( 'foo' )
# Specifies that this variant should be tagged ':latest'. This property will be useful in generation of content in README.md or ci files. Automatically populated as $false if unspecified
# tag_as_latest = $false
}
)

# This is a special global that sets a common buildContextFiles definition for all variants
# Docker image variants' definitions (shared)
$VARIANTS_SHARED = @{
buildContextFiles = @{
templates = @{
# The path of the template to process, relative to the templates directory, omitting the '.ps1' extension
'Dockerfile' = @{
# Specifies whether the template is common (shared) across distros
common = $false
# Specifies whether the template <file>.header.ps1 will be processed. Useful for Dockerfiles
includeHeader = $true
# Specifies whether the template <file>.footer.ps1 will be processed. Useful for Dockerfiles
includeFooter = $true
# Specifies a list of passes the template will be undergo, where each pass generates a file
common = $true
passes = @(
@{
# These variables will be available in $PASS_VARIABLES hashtable when this template is processed
variables = @{}
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@"
FROM alpine:3.8
echo "My tag is $( $VARIANT['tag'] )"
"@

if ('curl' -in $VARIANT['components']) {
@'
# Install curl
RUN apk update \
&& apk add --no-cache \
curl \
&& rm -rf /var/cache/apk/*
'@
}

if ('git' -in $VARIANT['components']) {
@'
# Install git
RUN apk update \
&& apk add --no-cache \
git \
&& rm -rf /var/cache/apk/*
'@
}

@'
CMD ["crond", "-f"]
'@

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
FROM alpine:3.8

echo "My tag is curl-git"
# Install curl
RUN apk update \
&& apk add --no-cache \
curl \
&& rm -rf /var/cache/apk/*

# Install git
RUN apk update \
&& apk add --no-cache \
git \
&& rm -rf /var/cache/apk/*

CMD ["crond", "-f"]
66 changes: 66 additions & 0 deletions docs/examples/basic-copies/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2

stages:
- build

.build_template: &build_definition
stage: build
only:
refs:
- branches
- /^v(?:\d+\.)+\d+$/
variables:
- $VARIANT_TAG
- $VARIANT_TAG_WITH_VERSION
- $VARIANT_BUILD_DIR
except:
refs:
- master
before_script:
- date '+%Y-%m-%d %H:%M:%S %z'

# Login to Docker Hub registry
- echo "${DOCKERHUB_REGISTRY_PASSWORD}" | docker login -u "${DOCKERHUB_REGISTRY_USER}" --password-stdin

# Login to GitLab registry
- echo "${CI_REGISTRY_PASSWORD}" | docker login -u "${CI_REGISTRY_USER}" --password-stdin "${CI_REGISTRY}"

script:
- date '+%Y-%m-%d %H:%M:%S %z'

- docker build
-t "${DOCKERHUB_REGISTRY_USER}/${CI_PROJECT_NAME}:${VARIANT_TAG}"
-t "${DOCKERHUB_REGISTRY_USER}/${CI_PROJECT_NAME}:${VARIANT_TAG_WITH_VERSION}"
-t "${CI_REGISTRY_IMAGE}:${VARIANT_TAG}"
-t "${CI_REGISTRY_IMAGE}:${VARIANT_TAG_WITH_VERSION}"
"${VARIANT_BUILD_DIR}"

- date '+%Y-%m-%d %H:%M:%S %z'

# Push to Docker Hub registry. E.g. 'namespace/my-project:tag'
- docker push "${DOCKERHUB_REGISTRY_USER}/${CI_PROJECT_NAME}:${VARIANT_TAG}"
- docker push "${DOCKERHUB_REGISTRY_USER}/${CI_PROJECT_NAME}:${VARIANT_TAG_WITH_VERSION}"

# Push to GitLab registry. E.g. 'registry.gitlab.com/namespace/my-project:tag
- docker push "${CI_REGISTRY_IMAGE}:${VARIANT_TAG}"
- docker push "${CI_REGISTRY_IMAGE}:${VARIANT_TAG_WITH_VERSION}"

after_script:
- date '+%Y-%m-%d %H:%M:%S %z'

# Log out of Docker Hub registry
- docker logout

# Log out of GitLab registry
- docker logout "${CI_REGISTRY}"

build-curl:
<<: *build_definition
variables:
VARIANT_TAG: curl
VARIANT_TAG_WITH_VERSION: curl-$CI_COMMIT_REF_NAME
VARIANT_BUILD_DIR: variants/curl
7 changes: 7 additions & 0 deletions docs/examples/basic-copies/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# basic

## Tags

| Tag | Dockerfile Build Context |
|:-------:|:---------:|
| `:curl` | [View](variants/curl ) |
1 change: 1 addition & 0 deletions docs/examples/basic-copies/app/index.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
4 changes: 4 additions & 0 deletions docs/examples/basic-copies/generate/definitions/FILES.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$FILES = @(
'.gitlab-ci.yml'
'README.md'
)
13 changes: 13 additions & 0 deletions docs/examples/basic-copies/generate/definitions/VARIANTS.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$VARIANTS = @(
@{
tag = 'curl'
}
)

$VARIANTS_SHARED = @{
buildContextFiles = @{
copies = @(
'/app'
)
}
}
75 changes: 75 additions & 0 deletions docs/examples/basic-copies/generate/templates/.gitlab-ci.yml.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
@'
image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
stages:
- build
.build_template: &build_definition
stage: build
only:
refs:
- branches
- /^v(?:\d+\.)+\d+$/
variables:
- $VARIANT_TAG
- $VARIANT_TAG_WITH_VERSION
- $VARIANT_BUILD_DIR
except:
refs:
- master
before_script:
- date '+%Y-%m-%d %H:%M:%S %z'
# Login to Docker Hub registry
- echo "${DOCKERHUB_REGISTRY_PASSWORD}" | docker login -u "${DOCKERHUB_REGISTRY_USER}" --password-stdin
# Login to GitLab registry
- echo "${CI_REGISTRY_PASSWORD}" | docker login -u "${CI_REGISTRY_USER}" --password-stdin "${CI_REGISTRY}"
script:
- date '+%Y-%m-%d %H:%M:%S %z'
- docker build
-t "${DOCKERHUB_REGISTRY_USER}/${CI_PROJECT_NAME}:${VARIANT_TAG}"
-t "${DOCKERHUB_REGISTRY_USER}/${CI_PROJECT_NAME}:${VARIANT_TAG_WITH_VERSION}"
-t "${CI_REGISTRY_IMAGE}:${VARIANT_TAG}"
-t "${CI_REGISTRY_IMAGE}:${VARIANT_TAG_WITH_VERSION}"
"${VARIANT_BUILD_DIR}"
- date '+%Y-%m-%d %H:%M:%S %z'
# Push to Docker Hub registry. E.g. 'namespace/my-project:tag'
- docker push "${DOCKERHUB_REGISTRY_USER}/${CI_PROJECT_NAME}:${VARIANT_TAG}"
- docker push "${DOCKERHUB_REGISTRY_USER}/${CI_PROJECT_NAME}:${VARIANT_TAG_WITH_VERSION}"
# Push to GitLab registry. E.g. 'registry.gitlab.com/namespace/my-project:tag
- docker push "${CI_REGISTRY_IMAGE}:${VARIANT_TAG}"
- docker push "${CI_REGISTRY_IMAGE}:${VARIANT_TAG_WITH_VERSION}"
after_script:
- date '+%Y-%m-%d %H:%M:%S %z'
# Log out of Docker Hub registry
- docker logout
# Log out of GitLab registry
- docker logout "${CI_REGISTRY}"
'@

$( $VARIANTS | % {
@"
build-$( $_['tag'] ):
<<: *build_definition
variables:
VARIANT_TAG: $( $_['tag'] )
VARIANT_TAG_WITH_VERSION: $( $_['tag'] )-`$CI_COMMIT_REF_NAME
VARIANT_BUILD_DIR: $( $_['build_dir_rel'] )
"@
})
Loading

0 comments on commit 9258c97

Please sign in to comment.