Skip to content

Commit

Permalink
Add container image (#306)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Berendt <[email protected]>
  • Loading branch information
berendt authored Apr 3, 2022
1 parent 86ec466 commit 5e7644d
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extends": [
"github>osism/renovate-config"
"github>osism/renovate-config",
"github>osism/renovate-config:docker"
]
}
37 changes: 37 additions & 0 deletions .github/workflows/build-container-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: Build container image

"on":
workflow_dispatch:
schedule:
- cron: "0 22 * * *"
push:
branches:
- main
pull_request:

jobs:
build-container-image:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Build container image
run: scripts/build.sh
env:
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
GIT_SHA: ${{ github.sha }}
REPOSITORY: osism/cookiecutter

- name: Push container image
run: |
scripts/push.sh
env:
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
REPOSITORY: osism/cookiecutter
if: |
github.repository == 'osism/cfg-cookiecutter' &&
github.ref == 'refs/heads/main'
23 changes: 23 additions & 0 deletions .github/workflows/check-docker-syntax.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: Check docker syntax

"on":
push:
paths:
- "Containerfile"
- .github/workflows/check-docker-syntax.yml
branches:
- main
pull_request:
paths:
- "Containerfile"
- .github/workflows/check-docker-syntax.yml

jobs:
check-docker-syntax:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: hadolint/[email protected]
with:
dockerfile: Containerfile
2 changes: 1 addition & 1 deletion .github/workflows/check-python-syntax.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ name: Check python syntax

jobs:
check-python-syntax:
runs-on: self-hosted
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-yaml-syntax.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ name: Check yaml syntax

jobs:
check-yaml-syntax:
runs-on: self-hosted
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-cookiecutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name: Test cookiecutter

jobs:
test-cookiecutter:
runs-on: self-hosted
runs-on: ubuntu-latest
strategy:
matrix:
openstack-version:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.venv
.tox
cfg-customer
output
34 changes: 34 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
ARG PYTHON_VERSION=3.9
FROM python:${PYTHON_VERSION}-alpine

COPY . /data

# hadolint ignore=DL3018
RUN apk add --no-cache \
bash \
git \
openssh-keygen \
pwgen \
&& apk add --no-cache --virtual .build-deps \
build-base \
cargo \
libffi-dev \
openssl-dev \
python3-dev \
rust \
&& pip3 --no-cache-dir install --upgrade 'pip==22.0.4' \
&& pip3 --no-cache-dir install -r /data/requirements.txt \
&& apk del .build-deps \
&& mkdir /output

WORKDIR /data

VOLUME ["/output"]
CMD ["cookiecutter", "-o", "/output", "/data"]

LABEL "org.opencontainers.image.documentation"="https://docs.osism.tech" \
"org.opencontainers.image.licenses"="ASL 2.0" \
"org.opencontainers.image.source"="https://github.com/osism/cfg-cookiecutter" \
"org.opencontainers.image.url"="https://www.osism.tech" \
"org.opencontainers.image.vendor"="OSISM GmbH" \
"org.opencontainers.image.title"="cookiecutter"
1 change: 1 addition & 0 deletions Dockerfile
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
# Cookiecutter template for an OSISM configuration repository

## Installation
## Usage with Docker

The `pwgen` tool must be installed.
Docker must be installed.

```
$ mkdir output
$ docker run --rm -v $(pwd)/output:/output -it quay.io/osism/cookiecutter
```

### Virtualenv
## Usage without Docker

The `pwgen` tool must be installed.

```
$ virtualenv -p python3 .venv
$ source .venv/bin/activate
$ pip3 install -r https://raw.githubusercontent.com/osism/cfg-cookiecutter/main/requirements.txt
```


## Usage

* http://cookiecutter.readthedocs.io/en/latest/

```
Expand Down
30 changes: 30 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -x

# Available environment variables
#
# BUILD_OPTS
# DOCKER_REGISTRY
# REPOSITORY
# VERSION

# Set default values

BUILD_OPTS=${BUILD_OPTS:-}
CREATED=$(date --rfc-3339=ns)
DOCKER_REGISTRY=${DOCKER_REGISTRY:-quay.io}
REVISION=$(git rev-parse HEAD)
VERSION=${VERSION:-latest}

if [[ -n $DOCKER_REGISTRY ]]; then
REPOSITORY="$DOCKER_REGISTRY/$REPOSITORY"
fi

buildah build-using-dockerfile \
--format docker \
--build-arg "VERSION=$VERSION" \
--tag "$(git rev-parse --short HEAD)" \
--label "org.opencontainers.image.created=$CREATED" \
--label "org.opencontainers.image.revision=$REVISION" \
--label "org.opencontainers.image.version=$VERSION" \
$BUILD_OPTS .
22 changes: 22 additions & 0 deletions scripts/push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -x

# Available environment variables
#
# DOCKER_REGISTRY
# REPOSITORY
# VERSION

# Set default values

DOCKER_REGISTRY=${DOCKER_REGISTRY:-quay.io}
VERSION=${VERSION:-latest}

if [[ -n $DOCKER_REGISTRY ]]; then
REPOSITORY="$DOCKER_REGISTRY/$REPOSITORY"
fi

buildah login --password $DOCKER_PASSWORD --username $DOCKER_USERNAME $DOCKER_REGISTRY

buildah tag "$(git rev-parse --short HEAD)" "$REPOSITORY:$VERSION"
buildah push "$REPOSITORY:$VERSION"

0 comments on commit 5e7644d

Please sign in to comment.