Skip to content

Commit

Permalink
initial commit opensign
Browse files Browse the repository at this point in the history
  • Loading branch information
compgeniuses committed May 31, 2024
1 parent 1551200 commit ab73fb0
Show file tree
Hide file tree
Showing 22 changed files with 202 additions and 184 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/javascript-node
{
"name": "ns8-kickstart",
"name": "ns8-opensign",
"image": "mcr.microsoft.com/devcontainers/javascript-node:0-18-bullseye",
// Configure tool-specific properties.
"customizations": {
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clean-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ jobs:
steps:
- uses: NethServer/ns8-github-actions/.github/actions/delete-image@v1
with:
images: "kickstart"
images: "opensign"
delete_image_token: ${{ secrets.IMAGES_CLEANUP_TOKEN }}
14 changes: 7 additions & 7 deletions build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ set -e
# Prepare variables for later use
images=()
# The image will be pushed to GitHub container registry
repobase="${REPOBASE:-ghcr.io/nethserver}"
repobase="${REPOBASE:-ghcr.io/geniusdynamics}"
# Configure the image name
reponame="kickstart"
reponame="opensign"

# Create a new empty container image
container=$(buildah from scratch)

# Reuse existing nodebuilder-kickstart container, to speed up builds
if ! buildah containers --format "{{.ContainerName}}" | grep -q nodebuilder-kickstart; then
# Reuse existing nodebuilder-opensign container, to speed up builds
if ! buildah containers --format "{{.ContainerName}}" | grep -q nodebuilder-opensign; then
echo "Pulling NodeJS runtime..."
buildah from --name nodebuilder-kickstart -v "${PWD}:/usr/src:Z" docker.io/library/node:lts
buildah from --name nodebuilder-opensign -v "${PWD}:/usr/src:Z" docker.io/library/node:lts
fi

echo "Build static UI files with node..."
buildah run \
--workingdir=/usr/src/ui \
--env="NODE_OPTIONS=--openssl-legacy-provider" \
nodebuilder-kickstart \
nodebuilder-opensign \
sh -c "yarn install && yarn build"

# Add imageroot directory to the container image
Expand All @@ -45,7 +45,7 @@ buildah config --entrypoint=/ \
--label="org.nethserver.authorizations=traefik@node:routeadm" \
--label="org.nethserver.tcp-ports-demand=1" \
--label="org.nethserver.rootfull=0" \
--label="org.nethserver.images=docker.io/mariadb:10.11.5 docker.io/nginx:stable-alpine3.17" \
--label="org.nethserver.images=docker.io/mongo:7.0.9 docker.io/amolshejole/opensign:staging docker.io/amolshejole/opensignserver:staging" \
"${container}"
# Commit the image
buildah commit "${container}" "${repobase}/${reponame}"
Expand Down
4 changes: 2 additions & 2 deletions imageroot/actions/configure-module/80start_services
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ exec 1>&2

touch smarthost.env

systemctl --user enable kickstart.service
systemctl --user restart kickstart.service
systemctl --user enable opensign.service
systemctl --user restart opensign.service
10 changes: 5 additions & 5 deletions imageroot/actions/configure-module/validate-input.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Configure kickstart",
"$id": "http://nethserver.org/json-schema/task/input/kickstart/configure-module",
"description": "Configure kickstart",
"title": "Configure opensign",
"$id": "http://nethserver.org/json-schema/task/input/opensign/configure-module",
"description": "Configure opensign",
"examples": [
{
"host": "kickstart.domain.org",
"host": "opensign.domain.org",
"http2https": true,
"lets_encrypt": true
}
Expand All @@ -19,7 +19,7 @@
"properties": {
"host": {
"type": "string",
"description": "Host name for the application, like 'kickstart.domain.org'",
"description": "Host name for the application, like 'opensign.domain.org'",
"format": "hostname",
"pattern": "\\."
},
Expand Down
10 changes: 5 additions & 5 deletions imageroot/actions/get-configuration/validate-output.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Get kickstart settings",
"$id": "http://nethserver.org/json-schema/task/input/kickstart/get-configuration",
"description": "Get kickstart settings",
"title": "Get opensign settings",
"$id": "http://nethserver.org/json-schema/task/input/opensign/get-configuration",
"description": "Get opensign settings",
"examples": [
{
"host": "kickstart.domain.org",
"host": "opensign.domain.org",
"http2https": true,
"lets_encrypt": true
}
Expand All @@ -19,7 +19,7 @@
"properties": {
"host": {
"type": "string",
"description": "Host name for the application, like 'kickstart.domain.org'",
"description": "Host name for the application, like 'opensign.domain.org'",
"format": "idn-hostname"
},
"lets_encrypt": {
Expand Down
23 changes: 8 additions & 15 deletions imageroot/actions/restore-module/40restore_database
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,25 @@ exec 1>&2 # Redirect any output to the journal (stderr)

# Prepare an initialization script that restores the dump file
mkdir -vp initdb.d
mv -v kickstart.sql initdb.d
mv -v opensign.archive initdb.d
#do the bash file to restore and exit once done
cat - >initdb.d/zz_kickstart_restore.sh <<'EOS'
# Print additional information:
mysql --version
# The script is sourced, override entrypoint args and exit:
set -- true
docker_temp_server_stop
cat - >initdb.d/zz_opensign_restore.sh <<'EOS'
mongosh --eval 'db.dropDatabase();' opensign
mongorestore --archive=/docker-entrypoint-initdb.d/opensign.archive
exit 0
EOS

# once we exit we remove initdb.d
trap 'rm -rfv initdb.d/' EXIT

# we start a container to initiate a database and load the dump
# at the end of kickstart_restore.sh the dump is loaded and
# at the end of opensign_restore.sh the dump is loaded and
# we exit the container
podman run \
--rm \
--interactive \
--network=none \
--volume=./initdb.d:/docker-entrypoint-initdb.d:z \
--volume mysql-data:/var/lib/mysql/:Z \
--env MARIADB_ROOT_PASSWORD=Nethesis,1234 \
--env MARIADB_DATABASE=kickstart \
--env MARIADB_USER=kickstart \
--env MARIADB_PASSWORD=kickstart \
--volume ./initdb.d:/docker-entrypoint-initdb.d:z \
--volume mongo-app:/data/db:Z \
--replace --name=restore_db \
${MARIADB_IMAGE}
${MONGO_IMAGE}
2 changes: 1 addition & 1 deletion imageroot/bin/module-cleanup-state
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# SPDX-License-Identifier: GPL-3.0-or-later
#

rm -vf kickstart.sql
rm -vf opensign.archive
16 changes: 7 additions & 9 deletions imageroot/bin/module-dump-state
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#!/bin/bash

#
# Copyright (C) 2022 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#!/bin/bash

#
# Copyright (C) 2022 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

set -e

if ! systemctl --user -q is-active kickstart.service; then
if ! systemctl --user -q is-active opensign.service; then
exit 0
fi

podman exec mariadb-app mysqldump \
--databases kickstart \
--default-character-set=utf8mb4 \
--skip-dump-date \
--ignore-table=mysql.event \
--single-transaction \
--quick \
--add-drop-table > kickstart.sql
podman exec mongo-app mongodump --archive > opensign.archive
9 changes: 7 additions & 2 deletions imageroot/etc/state-include.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
# List here what you want to save during backup : volumes or file Path


state/kickstart.sql
volumes/kickstart-app
state/opensign.archive
volumes/mongo-app
volumes/mongo-configdb
volumes/./apps/OpenSign
volumes/usr/app/node_modules
volumes/./apps/OpenSignServer


42 changes: 0 additions & 42 deletions imageroot/systemd/user/kickstart-app.service

This file was deleted.

34 changes: 0 additions & 34 deletions imageroot/systemd/user/kickstart.service

This file was deleted.

40 changes: 0 additions & 40 deletions imageroot/systemd/user/mariadb-app.service

This file was deleted.

31 changes: 31 additions & 0 deletions imageroot/systemd/user/mongo-app.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# Copyright (C) 2022 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

[Unit]
Description=Podman mongo-app.service
BindsTo=opensign.service
After=opensign.service

[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n
EnvironmentFile=%S/state/environment
Restart=always
TimeoutStopSec=70
ExecStartPre=/bin/rm -f %t/mongo-app.pid %t/mongo-app.ctr-id
ExecStart=/usr/bin/podman run --conmon-pidfile %t/mongo-app.pid \
--cidfile %t/mongo-app.ctr-id --cgroups=no-conmon \
--pod-id-file %t/opensign.pod-id --replace -d --name mongo-app \
--volume mongo-app:/data/db:Z \
--volume mongo-configdb:/data/configdb:Z \
${MONGO_IMAGE}
ExecStop=/usr/bin/podman stop --ignore --cidfile %t/mongo-app.ctr-id -t 10
ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/mongo-app.ctr-id
ExecReload=/usr/bin/podman kill -s HUP mongo-app
SyslogIdentifier=%u
PIDFile=%t/mongo-app.pid
Type=forking

[Install]
WantedBy=default.target
36 changes: 36 additions & 0 deletions imageroot/systemd/user/opensign-client.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# Copyright (C) 2022 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

[Unit]
Description=Podman opensign-client.service
BindsTo=opensign.service
After=opensign.service mongo-app.service opensign-server.service

[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n
EnvironmentFile=%S/state/environment
EnvironmentFile=-%S/state/smarthost.env
WorkingDirectory=%S/state
Restart=always
TimeoutStopSec=70
ExecStartPre=/bin/mkdir -p tmp
ExecStartPre=/bin/rm -f %t/opensign-app.pid %t/opensign-app.ctr-id
ExecStartPre=-runagent discover-smarthost
ExecStart=/usr/bin/podman run --conmon-pidfile %t/opensign-app.pid \
--cidfile %t/opensign-app.ctr-id --cgroups=no-conmon \
--pod-id-file %t/opensign.pod-id --replace -d --name opensign-app \
--volume ./apps/OpenSign/:/usr/app \
--volume /usr/app/node_modules:z \
--env=OPENSIGN_* \
${OPENSIGN_IMAGE} npm star
ExecStop=/usr/bin/podman stop --ignore --cidfile %t/opensign-app.ctr-id -t 10
ExecReload=/usr/bin/podman kill -s HUP opensign-app
SyslogIdentifier=%u
ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/opensign-app.ctr-id
PIDFile=%t/opensign-app.pid
Type=forking

[Install]
WantedBy=default.target
Loading

0 comments on commit ab73fb0

Please sign in to comment.