Skip to content

Commit

Permalink
Merge pull request #1 from rwaffen/docker
Browse files Browse the repository at this point in the history
Docker
  • Loading branch information
rwaffen authored Apr 5, 2022
2 parents 4bd25d9 + 8546847 commit 4a3f939
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 35 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Publish Docker image

on:
# push:
# branches:
# - develop
workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ package-lock.json

# Git repo clones
/repos

# Vagrant
/.vagrant
120 changes: 120 additions & 0 deletions DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Build the container

There is a Dockerfile to build a container. This can be done with:

cd hdm
docker build -t hdm .

# hdm_env for docker

to have all the hdm external parts together we recommend to put this into a folder called `hdm_env`.
The structure might look like this:

hdm_env/
├── certs
│   ├── puppetdb.ca.pem
│   ├── puppetdb.cert.pem
│   └── puppetdb.key.pem
├── database.yml
├── db
│   ├── development.sqlite3
│   └── test.sqlite3
├── hdm.yml
├── hiera
│   └── hiera files ...
└── hiera.yaml

If you are running this directly on the puppet compiler the hiera directory might not be needed. But if you have hiera as a seperate repository this might be helpfull. You also can mount it directly in the compose file.

## hdm config example

development:
read_only: true
allow_encryption: false
puppet_db:
server: "https://puppetdb.example.com:8081"
pem:
key: "/hdm_env/certs/puppet.key.pem"
cert: "/hdm_env/certs/puppet.cert.pem"
ca_file: "/hdm_env/certs/puppet.ca.pem"
config_dir: "/etc/puppetlabs/code"

# if not set, the default value 'hiera.yaml' of your environment is used
hiera_config_file: "/hdm_env/hiera.yaml"


## hdm database config example

default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000

development:
<<: *default
database: /hdm_env/db/development.sqlite3

test:
<<: *default
database: /hdm_env/db/test.sqlite3

production:
<<: *default
database: /hdm_env/db/production.sqlite3

## hdm hiera config example (Optional)

This file can be used as default file for all ore only one environment. You dont need this if you have this already in your environment.

---
version: 5
defaults:
datadir: 'data'
data_hash: 'yaml_data'

hierarchy:
- name: "Hiera general Yaml"
paths:
- "os/%{::os.name}-%{::os.release.full}.yaml"
- "os/%{::os.name}-%{::os.release.major}.yaml"
- "os/%{::os.name}.yaml"
- "os/%{::os.family}-%{::os.release.major}.yaml"
- "os/%{::os.family}.yaml"

- name: "Puppet Environments"
path: "env/%{::environment}.yaml"

- name: "Common Yaml"
path: "common.yaml"

# Docker Compose

For docker compose see `docker-compose.yaml` or use this example:

---
version: "3.5"
services:
hdm:
image: betadots/hdm
container_name: hdm
environment:
- TZ=Europe/Berlin
volumes:
# folder to save the rails sqlite
- /hdm_env/db:/hdm_env/db
# certs to talk to puppetdb
- /hdm_env/certs:/hdm_env/certs:ro
# hdm main config
- { type: 'bind', source: '/hdm_env/hdm.yml', target: '/hdm/config/hdm.yml', read_only: true }
# hdm database config
- { type: 'bind', source: '/hdm_env/database.yml', target: '/hdm/config/database.yml', read_only: true }

##### mount hiera as data dir
- /hdm_env/hiera:/etc/puppetlabs/code/environments/pre_development/data:ro
- /hdm_env/hiera:/etc/puppetlabs/code/environments/development/data:ro
- /hdm_env/hiera:/etc/puppetlabs/code/environments/test/data:ro
- /hdm_env/hiera:/etc/puppetlabs/code/environments/production/data:ro

ports:
- 3000:3000
restart: unless-stopped
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM ruby:2.5.8
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" >> /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install -y build-essential npm nodejs yarn
RUN gem install bundler -v 2.2.15
RUN gem install bundler -v 2.3.6

ENV APP_HOME /hdm
RUN mkdir $APP_HOME
Expand Down
3 changes: 2 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ GEM

PLATFORMS
x86_64-darwin-20
x86_64-darwin-21
x86_64-linux

DEPENDENCIES
Expand Down Expand Up @@ -301,4 +302,4 @@ RUBY VERSION
ruby 2.5.8p224

BUNDLED WITH
2.2.17
2.3.6
25 changes: 1 addition & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,29 +121,7 @@ The example development puppet configuration can be found in the directory

## Docker

### Build

There is a Dockerfile to build a container. This can be done with:

cd hdm
docker build -t hdm .

### Docker Compose

For docker-compose see `docker-compose.yaml` or use this example:

---
version: '3.5'
services:
hdm:
image: example42/hdm:latest
container_name: hdm
volumes:
# keep db outside of container
- /srv/data/hdm/db:/hdm/data/db
ports:
- 3000:3000
restart: unless-stopped
[click me](DOCKER.md)

## Use git repositories instead of "live" yaml files

Expand Down Expand Up @@ -188,4 +166,3 @@ Any changes made to files from a git repository will be commited and pushed back
to the origin repository. Please note that HDM will not pull updates from the
origin repository and is **not** able to resolve possible conflicts, so you might
want to make sure that your repository is only edited by HDM.

24 changes: 24 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
config.vm.box = "betadots/centos8p6"
config.vm.network "forwarded_port", guest: 3000, host: 3000, host_ip: "127.0.0.1"

config.vm.synced_folder "../hdm_env", "/hdm_env"
config.vm.synced_folder ".", "/hdm"

config.vm.provider "virtualbox" do |vb|
vb.memory = "4096"
end

config.vm.provision "shell", inline: <<-SHELL
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli docker-compose-plugin containerd.io
sudo systemctl enable --now docker.service
SHELL
end
5 changes: 3 additions & 2 deletions bin/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

bundle exec rails db:create
bundle exec rails db:migrate
bundle exec rails db:seed
./bin/fake_puppet_db &
# bundle exec rails db:seed

# ./bin/fake_puppet_db &
bundle exec rails server -b 0.0.0.0
24 changes: 17 additions & 7 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@
version: "3.5"
services:
hdm:
image: example42/hdm:latest
image: betadots/hdm
container_name: hdm
environment:
- PUID=1001
- PGID=1001
- USER_UID=1001
- USER_GID=1001
- TZ=Europe/Berlin
# volumes:
# - /srv/data/hdm/db:/app/data/db
volumes:
# folder to save the rails sqlite
- /hdm_env/db:/hdm_env/db
# certs to talk to puppetdb
- /hdm_env/certs:/hdm_env/certs:ro
# hdm main config
- { type: 'bind', source: '/hdm_env/hdm.yml', target: '/hdm/config/hdm.yml', read_only: true }
# hdm database config
- { type: 'bind', source: '/hdm_env/database.yml', target: '/hdm/config/database.yml', read_only: true }

##### mount hiera as data dir
- /hdm_env/hiera:/etc/puppetlabs/code/environments/pre_development/data:ro
- /hdm_env/hiera:/etc/puppetlabs/code/environments/development/data:ro
- /hdm_env/hiera:/etc/puppetlabs/code/environments/test/data:ro
- /hdm_env/hiera:/etc/puppetlabs/code/environments/production/data:ro

ports:
- 3000:3000
restart: unless-stopped

0 comments on commit 4a3f939

Please sign in to comment.