From 80515b362728d7ab4a8196d636495b55fc3a2957 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Tue, 5 Apr 2022 09:56:21 +0200 Subject: [PATCH 01/15] update docker files --- Dockerfile | 2 +- Gemfile.lock | 3 ++- README.md | 4 ++-- docker-compose.yaml | 10 +++++++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index b06682bc..6bfece1b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index d8eebbe0..d5f7684d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -268,6 +268,7 @@ GEM PLATFORMS x86_64-darwin-20 + x86_64-darwin-21 x86_64-linux DEPENDENCIES @@ -301,4 +302,4 @@ RUBY VERSION ruby 2.5.8p224 BUNDLED WITH - 2.2.17 + 2.3.6 diff --git a/README.md b/README.md index b5f03ff0..0e7bd63a 100644 --- a/README.md +++ b/README.md @@ -136,11 +136,12 @@ For docker-compose see `docker-compose.yaml` or use this example: version: '3.5' services: hdm: - image: example42/hdm:latest + image: betadots/hdm:latest container_name: hdm volumes: # keep db outside of container - /srv/data/hdm/db:/hdm/data/db + - /srv/data/hdm/env:/etc/puppetlabs/code ports: - 3000:3000 restart: unless-stopped @@ -188,4 +189,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. - diff --git a/docker-compose.yaml b/docker-compose.yaml index f291a152..4affd71d 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,7 +2,7 @@ version: "3.5" services: hdm: - image: example42/hdm:latest + image: betadots/hdm:latest container_name: hdm environment: - PUID=1001 @@ -10,8 +10,12 @@ services: - USER_UID=1001 - USER_GID=1001 - TZ=Europe/Berlin - # volumes: - # - /srv/data/hdm/db:/app/data/db + volumes: + - /srv/data/hdm/db:/app/data/db + - /srv/data/hdm/env:/etc/puppetlabs/code + - /srv/data/hdm/hdm.yaml:/hdm/config/hdm.yaml + - /srv/data/hdm/master.key:/hdm/config/master.key + - /srv/data/hdm/credentials.yml.enc:/hdm/config/credentials.yml.enc ports: - 3000:3000 restart: unless-stopped From a190d607ce8f015186ebafeb77e90dc8cbdd808d Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Tue, 5 Apr 2022 15:56:29 +0200 Subject: [PATCH 02/15] update docker files to use docker in real world tests --- .gitignore | 3 ++ DOCKER.md | 120 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 25 +-------- bin/entry.sh | 5 +- docker-compose.yaml | 26 ++++++---- 5 files changed, 143 insertions(+), 36 deletions(-) create mode 100644 DOCKER.md diff --git a/.gitignore b/.gitignore index 476b3ec9..1f85efba 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,6 @@ package-lock.json # Git repo clones /repos + +# Vagrant +/.vagrant diff --git a/DOCKER.md b/DOCKER.md new file mode 100644 index 00000000..abbd86e5 --- /dev/null +++ b/DOCKER.md @@ -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 diff --git a/README.md b/README.md index 0e7bd63a..5b3d4a1d 100644 --- a/README.md +++ b/README.md @@ -121,30 +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: betadots/hdm:latest - container_name: hdm - volumes: - # keep db outside of container - - /srv/data/hdm/db:/hdm/data/db - - /srv/data/hdm/env:/etc/puppetlabs/code - ports: - - 3000:3000 - restart: unless-stopped +[click me](DOCKER.md) ## Use git repositories instead of "live" yaml files diff --git a/bin/entry.sh b/bin/entry.sh index f331f430..3712004b 100755 --- a/bin/entry.sh +++ b/bin/entry.sh @@ -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 diff --git a/docker-compose.yaml b/docker-compose.yaml index 4affd71d..daf1c23f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,20 +2,26 @@ version: "3.5" services: hdm: - image: betadots/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 - - /srv/data/hdm/env:/etc/puppetlabs/code - - /srv/data/hdm/hdm.yaml:/hdm/config/hdm.yaml - - /srv/data/hdm/master.key:/hdm/config/master.key - - /srv/data/hdm/credentials.yml.enc:/hdm/config/credentials.yml.enc + # 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 From cc154150b53a3fd155cf21262137ff5686be7717 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Tue, 5 Apr 2022 15:57:04 +0200 Subject: [PATCH 03/15] add Vagrantfile to use docker, because my mac version is currently broken --- Vagrantfile | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Vagrantfile diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 00000000..ed539c15 --- /dev/null +++ b/Vagrantfile @@ -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 From 854684708666b9c20611f1e42502880333036442 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Tue, 5 Apr 2022 15:57:38 +0200 Subject: [PATCH 04/15] add github action to build packages --- .github/workflows/build_docker.yml | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/build_docker.yml diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml new file mode 100644 index 00000000..0687429c --- /dev/null +++ b/.github/workflows/build_docker.yml @@ -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 }} From 5f84a2d9f75d8ded056317ca2eaa14cb94fec20f Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Tue, 5 Apr 2022 16:09:48 +0200 Subject: [PATCH 05/15] Update build_docker.yml --- .github/workflows/build_docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index 0687429c..d6cb7375 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -38,6 +38,6 @@ jobs: uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc with: context: . - push: false + push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} From e9ffd10d63e945fa4e94ae05cd6b9571d60aa91f Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Wed, 6 Apr 2022 14:45:46 +0200 Subject: [PATCH 06/15] update docker env. build docker based on alpine --- .dockerignore | 13 +++++++++---- DOCKER.md | 46 ++++++++++----------------------------------- Dockerfile | 45 +++++++++++++++++++++++++++++++++----------- Vagrantfile | 2 ++ bin/entry.sh | 4 +++- docker-compose.yaml | 15 +++++++++------ 6 files changed, 67 insertions(+), 58 deletions(-) diff --git a/.dockerignore b/.dockerignore index 956e7938..60a12fb6 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,9 +1,14 @@ .bundle/ +.dockerignore .git/ .gitignore -vendor/ -.dockerignore +.vagrant/ +db/*.sqlite3 docker-compose.yml Gemfile.lock -db/*.sqlite3 -log/*.log +log/ +node_modules/ +screenshots/ +test/ +tmp/ +vendor/ diff --git a/DOCKER.md b/DOCKER.md index abbd86e5..e73ec8a9 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -1,10 +1,3 @@ -# 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`. @@ -45,6 +38,8 @@ If you are running this directly on the puppet compiler the hiera directory migh ## hdm database config example +to save the SQLite DB files outside of the container, we habe to inject a different database.yml to change the path. When there is a mount into the container for hdm_env you might place it there, or change it to your desired location. + default: &default adapter: sqlite3 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> @@ -64,7 +59,7 @@ If you are running this directly on the puppet compiler the hiera directory migh ## 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. +This file can be used as default file for all or only one environment. You dont need this if you have this already in your environment. But it is usefull if you have a seperate hiera repository and only mounting pseudo environments into your docker. --- version: 5 @@ -89,32 +84,11 @@ This file can be used as default file for all ore only one environment. You dont # Docker Compose -For docker compose see `docker-compose.yaml` or use this example: +For docker compose see [`docker-compose.yaml`](docker-compose.yaml). - --- - 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 +# Build the container + +If you want to build the container locally, there is a Dockerfile for the container. This can be done with: + + cd hdm + docker build -t hdm . diff --git a/Dockerfile b/Dockerfile index 6bfece1b..d6452f04 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,45 @@ -FROM ruby:2.5.8 +FROM ruby:2.5.8-alpine as build -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.3.6 +RUN apk add --update --no-cache \ + nodejs \ + yarn ENV APP_HOME /hdm -RUN mkdir $APP_HOME WORKDIR $APP_HOME -COPY Gemfile $APP_HOME/ -RUN bundle config set --local path 'vendor/bundle' && bundle install +COPY package.json $APP_HOME +COPY yarn.lock $APP_HOME +RUN yarn install --check-files COPY . $APP_HOME -COPY config/hdm.yml.template $APP_HOME/config/hdm.yml -RUN yarn install --check-files +FROM ruby:2.5.8-alpine + +RUN apk add --update --no-cache \ + binutils-gold \ + build-base \ + g++ \ + gcc \ + libstdc++ \ + libffi-dev \ + libc-dev \ + libxml2-dev \ + libxslt-dev \ + libgcrypt-dev \ + make \ + sqlite \ + sqlite-dev \ + # not needed for gems, but for runtime + git \ + tzdata \ + # yarn # works without this but produces a short error, that yarn is not found + +RUN gem install bundler -v 2.3.6 + +COPY --from=build /hdm /hdm +WORKDIR /hdm -EXPOSE 3000 +RUN bundle check || bundle install --without test +# ENTRYPOINT ["/hdm/bin/entry.sh"] CMD ["/hdm/bin/entry.sh"] diff --git a/Vagrantfile b/Vagrantfile index ed539c15..221dddb4 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -14,11 +14,13 @@ Vagrant.configure("2") do |config| config.vm.provider "virtualbox" do |vb| vb.memory = "4096" + vb.cpus = 4 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 echo '{ "features": { "buildkit": true } }' > /etc/docker/daemon.json sudo systemctl enable --now docker.service SHELL end diff --git a/bin/entry.sh b/bin/entry.sh index 3712004b..e89693b6 100755 --- a/bin/entry.sh +++ b/bin/entry.sh @@ -1,4 +1,6 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh + +# cd /hdm bundle exec rails db:create bundle exec rails db:migrate diff --git a/docker-compose.yaml b/docker-compose.yaml index daf1c23f..05114172 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,7 +2,7 @@ version: "3.5" services: hdm: - image: betadots/hdm + image: ghcr.io/betadots/hdm container_name: hdm environment: - TZ=Europe/Berlin @@ -16,11 +16,14 @@ services: # 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 + ##### mount hiera as data dir in each pseudo env, if you have a seperate hiera repo + # - /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 + + ### mount actual code directory from puppetserver + # - /etc/puppetlabs/code/environments:/etc/puppetlabs/code/environments:ro ports: - 3000:3000 From c360593bfc42d9f6798e3bd7e238790a5c3f3dec Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Wed, 6 Apr 2022 14:49:59 +0200 Subject: [PATCH 07/15] fix typo in dockerfile --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d6452f04..488ac8b5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,8 +31,8 @@ RUN apk add --update --no-cache \ sqlite-dev \ # not needed for gems, but for runtime git \ - tzdata \ - # yarn # works without this but produces a short error, that yarn is not found + # yarn \ # works without this but produces a short error, that yarn is not found + tzdata RUN gem install bundler -v 2.3.6 From 411d310ff228e4a63390f1a1c906f2f8810b3495 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Wed, 6 Apr 2022 15:41:23 +0200 Subject: [PATCH 08/15] remove needed files from ignore --- .dockerignore | 3 --- 1 file changed, 3 deletions(-) diff --git a/.dockerignore b/.dockerignore index 60a12fb6..dda9a6cd 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,9 +6,6 @@ db/*.sqlite3 docker-compose.yml Gemfile.lock -log/ node_modules/ screenshots/ -test/ -tmp/ vendor/ From abf4e5471fed06145058a6af4c135239856637d2 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Wed, 6 Apr 2022 15:42:00 +0200 Subject: [PATCH 09/15] remove comment and change from entrypoint to cmd --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 488ac8b5..fde179ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,7 @@ COPY yarn.lock $APP_HOME RUN yarn install --check-files COPY . $APP_HOME +COPY config/hdm.yml.template $APP_HOME/config/hdm.yml FROM ruby:2.5.8-alpine @@ -41,5 +42,4 @@ WORKDIR /hdm RUN bundle check || bundle install --without test -# ENTRYPOINT ["/hdm/bin/entry.sh"] CMD ["/hdm/bin/entry.sh"] From a81cd11bbdefd90593b15b4e20e7be9a87990260 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Wed, 6 Apr 2022 15:42:27 +0200 Subject: [PATCH 10/15] make sure /etc/docker exists --- Vagrantfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Vagrantfile b/Vagrantfile index 221dddb4..bf0fe536 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -20,6 +20,7 @@ Vagrant.configure("2") do |config| 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 mkdir -p /etc/docker sudo echo '{ "features": { "buildkit": true } }' > /etc/docker/daemon.json sudo systemctl enable --now docker.service SHELL From 3835774d3e5cd4ee36dd26ccbd7e16d5bdf6038a Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Wed, 6 Apr 2022 15:43:05 +0200 Subject: [PATCH 11/15] add env var to enable dev mode --- .env | 1 + bin/entry.sh | 7 +++++-- docker-compose.yaml | 11 +++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 00000000..93a64151 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +DEVELOP=0 diff --git a/bin/entry.sh b/bin/entry.sh index e89693b6..757b9300 100755 --- a/bin/entry.sh +++ b/bin/entry.sh @@ -4,7 +4,10 @@ bundle exec rails db:create bundle exec rails db:migrate -# bundle exec rails db:seed -# ./bin/fake_puppet_db & +if [[ $DEVELOP -eq 1 ]]; then +bundle exec rails db:seed +./bin/fake_puppet_db & +fi + bundle exec rails server -b 0.0.0.0 diff --git a/docker-compose.yaml b/docker-compose.yaml index 05114172..694efd85 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,19 +2,22 @@ version: "3.5" services: hdm: - image: ghcr.io/betadots/hdm + # image: ghcr.io/betadots/hdm + image: hdm container_name: hdm environment: - TZ=Europe/Berlin + # whether to enable dev mode with fake puppetdb or not + # - DEVELOP=1 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_env/certs:/hdm_env/certs:ro # hdm main config - - { type: 'bind', source: '/hdm_env/hdm.yml', target: '/hdm/config/hdm.yml', read_only: true } + # - { 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 } + # - { type: 'bind', source: '/hdm_env/database.yml', target: '/hdm/config/database.yml', read_only: true } ##### mount hiera as data dir in each pseudo env, if you have a seperate hiera repo # - /hdm_env/hiera:/etc/puppetlabs/code/environments/pre_development/data:ro From eea648cc5d1af5eef122fd7349742e914642fab0 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Wed, 6 Apr 2022 18:37:11 +0200 Subject: [PATCH 12/15] update docu to clarify some things --- DOCKER.md | 24 ++++++++++++++++++------ README.md | 2 +- bin/entry.sh | 2 -- docker-compose.yaml | 35 +++++++++++++++++------------------ 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/DOCKER.md b/DOCKER.md index e73ec8a9..d6a6cfb5 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -11,7 +11,8 @@ The structure might look like this: ├── database.yml ├── db │   ├── development.sqlite3 - │   └── test.sqlite3 + │   ├── ... + │   └── production.sqlite3 ├── hdm.yml ├── hiera │   └── hiera files ... @@ -19,8 +20,14 @@ The structure might look like this: 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. +To avoid any trouble with access to the cert files, it might be better to copy them to certs/ directory and adjust the mode so you can use them for sure. + +The db folder might be a volume mounted into your container to save the user database outside of the container. + ## hdm config example +This file is used inside the container, so paths have to match to your mounted docker volume. + development: read_only: true allow_encryption: false @@ -38,7 +45,9 @@ If you are running this directly on the puppet compiler the hiera directory migh ## hdm database config example -to save the SQLite DB files outside of the container, we habe to inject a different database.yml to change the path. When there is a mount into the container for hdm_env you might place it there, or change it to your desired location. +This file is used inside the container, so paths have to match to your mounted docker volume. + +To save the SQLite DB files outside of the container, we habe to inject a different database.yml to change the path. default: &default adapter: sqlite3 @@ -59,7 +68,9 @@ to save the SQLite DB files outside of the container, we habe to inject a differ ## hdm hiera config example (Optional) -This file can be used as default file for all or only one environment. You dont need this if you have this already in your environment. But it is usefull if you have a seperate hiera repository and only mounting pseudo environments into your docker. +This file is used inside the container, so paths have to match to your mounted docker volume. + +This file can be used as default file for all or only one environment. You dont need this if you have this already in your environment. But it can be usefull if you have a seperate hiera repository and only mounting pseudo environments into your docker (see [docker-compose](docker-compose.yaml) example). --- version: 5 @@ -84,11 +95,12 @@ This file can be used as default file for all or only one environment. You dont # Docker Compose -For docker compose see [`docker-compose.yaml`](docker-compose.yaml). +See [`docker-compose.yaml`](docker-compose.yaml). # Build the container -If you want to build the container locally, there is a Dockerfile for the container. This can be done with: +If you want to build the container locally, use the Dockerfile from this repo. +If you don't use BuildKit yet, give it a try. cd hdm - docker build -t hdm . + DOCKER_BUILDKIT=1 docker build -t hdm . diff --git a/README.md b/README.md index 5b3d4a1d..0f97b9e1 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ The example development puppet configuration can be found in the directory ## Docker -[click me](DOCKER.md) +See [DOCKER.md](DOCKER.md) ## Use git repositories instead of "live" yaml files diff --git a/bin/entry.sh b/bin/entry.sh index 757b9300..b2d58a22 100755 --- a/bin/entry.sh +++ b/bin/entry.sh @@ -1,7 +1,5 @@ #!/usr/bin/env sh -# cd /hdm - bundle exec rails db:create bundle exec rails db:migrate diff --git a/docker-compose.yaml b/docker-compose.yaml index 694efd85..d40277b3 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,31 +2,30 @@ version: "3.5" services: hdm: - # image: ghcr.io/betadots/hdm - image: hdm + image: ghcr.io/betadots/hdm:main container_name: hdm environment: - TZ=Europe/Berlin # whether to enable dev mode with fake puppetdb or not # - DEVELOP=1 - 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 } + # volumes: + # #### folder to save the user sqlite db + # - /hdm_env/db:/hdm_env/db + # #### certs for talking to the 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 in each pseudo env, if you have a seperate hiera repo - # - /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 + # #### mount hiera as data dir in each pseudo env, if you have a seperate hiera repo + # - /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 - ### mount actual code directory from puppetserver - # - /etc/puppetlabs/code/environments:/etc/puppetlabs/code/environments:ro + # #### mount actual code directory from puppetserver + # - /etc/puppetlabs/code/environments:/etc/puppetlabs/code/environments:ro ports: - 3000:3000 From 99c261722493c1a4e3b02ff6cf91debd4826c9bf Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Wed, 6 Apr 2022 18:40:31 +0200 Subject: [PATCH 13/15] build container on push to main or tag --- .github/workflows/build_docker.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index d6cb7375..f25ac315 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -1,9 +1,10 @@ name: Publish Docker image on: - # push: - # branches: - # - develop + push: + branches: ['main'] + tags: + - '*' workflow_dispatch: env: From d9e5557af03fcc9eb38b541f8b39b788185ae61c Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Wed, 6 Apr 2022 18:42:01 +0200 Subject: [PATCH 14/15] keep the same style --- .github/workflows/build_docker.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index f25ac315..cf9de937 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -2,7 +2,8 @@ name: Publish Docker image on: push: - branches: ['main'] + branches: + - 'main' tags: - '*' workflow_dispatch: From d05a7d52c3579e5ad0641a9954a5ab830725584d Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Thu, 7 Apr 2022 09:04:11 +0200 Subject: [PATCH 15/15] use facts hash instead of top scope Co-authored-by: Tim Meusel --- DOCKER.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/DOCKER.md b/DOCKER.md index d6a6cfb5..7bb42a58 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -81,11 +81,11 @@ This file can be used as default file for all or only one environment. You dont 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" + - "os/%{facts.os.name}-%{facts.os.release.full}.yaml" + - "os/%{facts.os.name}-%{facts.os.release.major}.yaml" + - "os/%{facts.os.name}.yaml" + - "os/%{facts.os.family}-%{facts.os.release.major}.yaml" + - "os/%{facts.os.family}.yaml" - name: "Puppet Environments" path: "env/%{::environment}.yaml"