From 07ebd0facdee3bd1b7e276a6353f2f1d2b600889 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Sat, 27 Nov 2021 13:31:34 +0100 Subject: [PATCH] added go-aptproxy state --- states/go-aptproxy/defaults.yaml | 11 +++++++++++ states/go-aptproxy/init.sls | 4 ++++ states/go-aptproxy/install.sls | 26 ++++++++++++++++++++++++++ states/go-aptproxy/kernelmap.yaml | 3 +++ states/go-aptproxy/map.jinja | 14 ++++++++++++++ states/go-aptproxy/osarchmap.yaml | 21 +++++++++++++++++++++ states/go-aptproxy/qrz.service.j2 | 17 +++++++++++++++++ states/go-aptproxy/service.sls | 14 ++++++++++++++ 8 files changed, 110 insertions(+) create mode 100644 states/go-aptproxy/defaults.yaml create mode 100644 states/go-aptproxy/init.sls create mode 100644 states/go-aptproxy/install.sls create mode 100644 states/go-aptproxy/kernelmap.yaml create mode 100644 states/go-aptproxy/map.jinja create mode 100644 states/go-aptproxy/osarchmap.yaml create mode 100644 states/go-aptproxy/qrz.service.j2 create mode 100644 states/go-aptproxy/service.sls diff --git a/states/go-aptproxy/defaults.yaml b/states/go-aptproxy/defaults.yaml new file mode 100644 index 0000000..798f09d --- /dev/null +++ b/states/go-aptproxy/defaults.yaml @@ -0,0 +1,11 @@ +--- +go-aptproxy: + enabled: true + install_dir: /usr/local/apps + release_dir: /usr/local/apps/releases + working_dir: /var/cache/go-aptproxy + port: 8000 + mirror: https://git.paulbsd.com/paulbsd/go-aptproxy/releases/download + version: 1.0.0 + os: linux + arch: amd64 diff --git a/states/go-aptproxy/init.sls b/states/go-aptproxy/init.sls new file mode 100644 index 0000000..b71e4b0 --- /dev/null +++ b/states/go-aptproxy/init.sls @@ -0,0 +1,4 @@ +--- +include: + - .install + - .service diff --git a/states/go-aptproxy/install.sls b/states/go-aptproxy/install.sls new file mode 100644 index 0000000..6a49b69 --- /dev/null +++ b/states/go-aptproxy/install.sls @@ -0,0 +1,26 @@ +--- +{%- from "go-aptproxy/map.jinja" import go-aptproxy with context %} +go-aptproxy-archive-extract: + archive.extracted: + - name: {{ go-aptproxy.release_dir }}/go-aptproxy-{{ go-aptproxy.version }} + - source: {{ go-aptproxy.mirror }}/{{ go-aptproxy.version }}/go-aptproxy-{{ go-aptproxy.version }}-{{ go-aptproxy.os }}-{{ go-aptproxy.arch }}.tar.gz + - skip_verify: true + - enforce_toplevel: false + - if_missing: {{ go-aptproxy.release_dir }}/go-aptproxy-{{ go-aptproxy.version }} + - watch_in: + - service: go-aptproxy-service + +go-aptproxy-binary-symlink: + file.symlink: + - name: {{ go-aptproxy.install_dir }}/go-aptproxy + - target: {{ go-aptproxy.release_dir }}/go-aptproxy-{{ go-aptproxy.version }} + - require: + - archive: go-aptproxy-archive-extract + - watch_in: + - service: go-aptproxy-service + +go-aptproxy-cleanup: + software.cleanup: + - name: go-aptproxy + - path: {{ go-aptproxy.release_dir }} + - version: {{ go-aptproxy.version }} diff --git a/states/go-aptproxy/kernelmap.yaml b/states/go-aptproxy/kernelmap.yaml new file mode 100644 index 0000000..40943f2 --- /dev/null +++ b/states/go-aptproxy/kernelmap.yaml @@ -0,0 +1,3 @@ +--- +Linux: + os: "linux" diff --git a/states/go-aptproxy/map.jinja b/states/go-aptproxy/map.jinja new file mode 100644 index 0000000..71222df --- /dev/null +++ b/states/go-aptproxy/map.jinja @@ -0,0 +1,14 @@ +{%- import_yaml "go-aptproxy/defaults.yaml" as default_settings -%} + +{%- import_yaml "go-aptproxy/kernelmap.yaml" as kernelmap -%} +{%- import_yaml "go-aptproxy/osarchmap.yaml" as osarchmap -%} + +{%- set defaults = salt['grains.filter_by'](default_settings, + default='go-aptproxy', + merge=salt['grains.filter_by'](osarchmap, grain='osarch', + merge=salt['grains.filter_by'](kernelmap, grain='kernel') + ) + ) +-%} + +{%- set go-aptproxy = salt['pillar.get']('go-aptproxy', default=defaults, merge=True) -%} \ No newline at end of file diff --git a/states/go-aptproxy/osarchmap.yaml b/states/go-aptproxy/osarchmap.yaml new file mode 100644 index 0000000..4bd82f8 --- /dev/null +++ b/states/go-aptproxy/osarchmap.yaml @@ -0,0 +1,21 @@ +--- +amd64: + arch: "amd64" + +x86_64: + arch: "amd64" + +386: + arch: "386" + +arm64: + arch: "arm64" + +armv6l: + arch: "arm" + +armv7l: + arch: "arm" + +armhf: + arch: "arm" diff --git a/states/go-aptproxy/qrz.service.j2 b/states/go-aptproxy/qrz.service.j2 new file mode 100644 index 0000000..4f5c626 --- /dev/null +++ b/states/go-aptproxy/qrz.service.j2 @@ -0,0 +1,17 @@ +## {{ salt['pillar.get']('salt_managed', default='Salt Managed') }} +{%- from "go-aptproxy/map.jinja" import go-aptproxy with context %} +[Unit] +Description=go-aptproxy +Documentation=https://git.paulbsd.com/paulbsd/go-aptproxy +After=network.target + +[Service] +Type=simple +ExecStart={{ go-aptproxy.install_dir }}/go-aptproxy/go-aptproxy -directory {{ go-aptproxy.working_dir }} -port {{ go-aptproxy.port }} +ExecReload=/bin/kill -HUP $MAINPID +Restart=on-failure +RestartForceExitStatus=SIGPIPE +KillMode=control-group + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/states/go-aptproxy/service.sls b/states/go-aptproxy/service.sls new file mode 100644 index 0000000..27f631f --- /dev/null +++ b/states/go-aptproxy/service.sls @@ -0,0 +1,14 @@ +--- +{%- from "go-aptproxy/map.jinja" import go-aptproxy with context %} +go-aptproxy-service-file: + file.managed: + - name: /etc/systemd/system/go-aptproxy.service + - source: salt://go-aptproxy/go-aptproxy.service.j2 + - user: root + - group: root + - template: jinja + +go-aptproxy-service: + service.running: + - name: go-aptproxy + - enable: true