From 65acc48d9aa473be46b28a4c21520c89be446131 Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Sat, 18 May 2024 20:47:58 +0200 Subject: [PATCH 01/20] Fix building mkdocs (#900) * Build mkdocs to gh-pages * rename requirements.pip to requirements.txt * exclude requirements from doc deployment * add docs python to dependabot * fix wrong merge * bring back Upload artifact action --- .github/dependabot.yml | 5 +++++ .github/workflows/docs.yaml | 8 ++++---- .readthedocs.yaml | 2 +- Makefile | 4 ++-- docs/{requirements.pip => requirements.txt} | 2 +- mkdocs.yml | 3 +++ 6 files changed, 16 insertions(+), 8 deletions(-) rename docs/{requirements.pip => requirements.txt} (85%) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 5286f7f65..3e9267eda 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -13,3 +13,8 @@ updates: - "aelsabbahy" open-pull-requests-limit: 0 + - package-ecosystem: "pip" + directory: "/docs" + schedule: + interval: "weekly" + day: "saturday" diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 6a80c4abd..91c39a51f 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -30,18 +30,18 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: - python-version: "3.11" + python-version: "3.12" cache: 'pip' - name: Install dependencies run: | pip install --upgrade pip - pip install --requirement docs/requirements.pip + pip install --requirement docs/requirements.txt - name: Build documentation run: mkdocs build # To remove if not using github pages - name: Upload artifact - uses: actions/upload-pages-artifact@v2 + uses: actions/upload-pages-artifact@v3 with: path: site diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 3166424d8..015eb5de8 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -16,4 +16,4 @@ mkdocs: # Optionally declare the Python requirements required to build your docs python: install: - - requirements: docs/requirements.pip + - requirements: docs/requirements.txt diff --git a/Makefile b/Makefile index dfbac4da0..6d4cf159c 100644 --- a/Makefile +++ b/Makefile @@ -140,10 +140,10 @@ $(PYTHON): $(info Creating virtualenv in $(VENV)) @python -m venv $(VENV) -$(DOCS_DEPS): $(PYTHON) docs/requirements.pip +$(DOCS_DEPS): $(PYTHON) docs/requirements.txt $(info Installing dependencies) @pip install --upgrade pip - @pip install --requirement docs/requirements.pip + @pip install --requirement docs/requirements.txt @touch $(DOCS_DEPS) docs/setup: $(DOCS_DEPS) diff --git a/docs/requirements.pip b/docs/requirements.txt similarity index 85% rename from docs/requirements.pip rename to docs/requirements.txt index cfa4c09da..58910536a 100644 --- a/docs/requirements.pip +++ b/docs/requirements.txt @@ -1,6 +1,6 @@ mkdocs-material==9.5.3 mkdocs-macros-plugin==1.0.5 mkdocs-awesome-pages-plugin==2.9.2 +mkdocs-exclude==1.0.2 mdx-breakless-lists==1.0.1 pygments==2.17.2 - diff --git a/mkdocs.yml b/mkdocs.yml index 547aaaa90..df2a127ff 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -46,6 +46,9 @@ plugins: - awesome-pages - macros: render_by_default: false + - exclude: + glob: + - requirements.txt markdown_extensions: - abbr From 71bc379493de6936c8993cbfaacab76b5ffa67ce Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Sun, 19 May 2024 09:08:08 +0200 Subject: [PATCH 02/20] Update docs to fix linting issues (#904) * add README to linter config * fix MD004/ul-style in cli.md * fix mkdocs import content from other files * fix line length in migrations.doc * add extras to linter * fix extra README * fix line length in dgoss README * bump markdownlint-cli2-action@v16 --------- Co-authored-by: Ahmed Elsabbahy --- .github/workflows/docs.yaml | 5 +++- docs/cli.md | 38 +++++++++++++++---------------- docs/containers/docker-compose.md | 1 + docs/containers/docker.md | 1 + docs/containers/kubernetes.md | 1 + docs/contributing.md | 1 + docs/license.md | 1 + docs/migrations.md | 4 ++-- extras/dcgoss/README.md | 19 ++++++++++------ extras/dgoss/README.md | 24 +++++++++++++------ extras/kgoss/README.md | 4 ++-- 11 files changed, 61 insertions(+), 38 deletions(-) diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 91c39a51f..94ae98b6b 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -20,10 +20,13 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: DavidAnson/markdownlint-cli2-action@v13 + - uses: DavidAnson/markdownlint-cli2-action@v16 with: globs: | docs/**/*.md + README.md + extras/**/README.md + .github/CONTRIBUTING.md build: runs-on: ubuntu-latest diff --git a/docs/cli.md b/docs/cli.md index d7b1bf62e..f72b0bfb4 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -62,12 +62,12 @@ GLOBAL OPTIONS: ## Commands Commands are the actions goss can run. -- [add](#add): add a single test for a resource -- [autoadd](#autoadd): automatically add multiple tests for a resource -- [render](#render): renders and outputs the gossfile, importing all included gossfiles -- [serve](#serve): serves the gossfile validation as an HTTP endpoint on a specified address and port, +* [add](#add): add a single test for a resource +* [autoadd](#autoadd): automatically add multiple tests for a resource +* [render](#render): renders and outputs the gossfile, importing all included gossfiles +* [serve](#serve): serves the gossfile validation as an HTTP endpoint on a specified address and port, so you can use your gossfile as a health report for the host -- [validate](#validate): runs the goss test suite on your server +* [validate](#validate): runs the goss test suite on your server ### `add` @@ -123,22 +123,22 @@ A sub-command *resource type* has to be provided when running `add`. Automatically [adds](#add) all **existing** resources matching the provided argument. Will automatically add the following matching resources: -- `file` - only if argument contains `/` -- `group` -- `package` -- `port` -- `process` - Also adding any ports it's listening to (if run as root) -- `service` -- `user` +* `file` - only if argument contains `/` +* `group` +* `package` +* `port` +* `process` - Also adding any ports it's listening to (if run as root) +* `service` +* `user` Will **NOT** automatically add: -- `addr` -- `command` - for safety -- `dns` -- `http` -- `interface` -- `kernel-param` -- `mount` +* `addr` +* `command` - for safety +* `dns` +* `http` +* `interface` +* `kernel-param` +* `mount` !!! example ```console diff --git a/docs/containers/docker-compose.md b/docs/containers/docker-compose.md index 9219adf97..3955acc5a 100644 --- a/docs/containers/docker-compose.md +++ b/docs/containers/docker-compose.md @@ -1 +1,2 @@ + --8<-- "extras/dcgoss/README.md" diff --git a/docs/containers/docker.md b/docs/containers/docker.md index 07daf5c87..e17d0e635 100644 --- a/docs/containers/docker.md +++ b/docs/containers/docker.md @@ -1 +1,2 @@ + --8<-- "extras/dgoss/README.md" diff --git a/docs/containers/kubernetes.md b/docs/containers/kubernetes.md index b696d2f54..83a0bbb53 100644 --- a/docs/containers/kubernetes.md +++ b/docs/containers/kubernetes.md @@ -1 +1,2 @@ + --8<-- "extras/kgoss/README.md" diff --git a/docs/contributing.md b/docs/contributing.md index 0c7bc9cbf..1a1055c5e 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -1 +1,2 @@ + --8<-- ".github/CONTRIBUTING.md" diff --git a/docs/license.md b/docs/license.md index f409d4523..e47f1b546 100644 --- a/docs/license.md +++ b/docs/license.md @@ -1 +1,2 @@ + --8<-- "LICENSE" diff --git a/docs/migrations.md b/docs/migrations.md index f6981f4c0..9b4ef5ec4 100644 --- a/docs/migrations.md +++ b/docs/migrations.md @@ -16,8 +16,8 @@ user: - root ``` -Goss v0.4.x, will fail with the above as group "root" is only in the slice once. However, with goss v0.4.x the array may contain -matchers. The test below is valid for v0.4.x but not valid for v0.3.x +Goss v0.4.x, will fail with the above as group "root" is only in the slice once. However, with goss v0.4.x the array may +contain matchers. The test below is valid for v0.4.x but not valid for v0.3.x ```yaml user: diff --git a/extras/dcgoss/README.md b/extras/dcgoss/README.md index 06d64498a..9eedf65ec 100644 --- a/extras/dcgoss/README.md +++ b/extras/dcgoss/README.md @@ -1,6 +1,7 @@ # dcgoss -dcgoss is a convenience wrapper around goss that aims to bring the simplicity of goss to docker-compose managed containers. It is based on `dgoss`. +dcgoss is a convenience wrapper around goss that aims to bring the simplicity of goss to docker-compose managed +containers. It is based on `dgoss`. ## Usage @@ -8,7 +9,9 @@ dcgoss is a convenience wrapper around goss that aims to bring the simplicity of ### Run -Run is used to validate a docker container defined in `docker-compose.yml`. It expects both a `docker-compose.yml` and `goss.yaml` file to exist in the directory it was invoked from. Container configuration is used from the compose file, for example: +Run is used to validate a docker container defined in `docker-compose.yml`. It expects both a `docker-compose.yml` +and `goss.yaml` file to exist in the directory it was invoked from. Container configuration is used from the +compose file, for example: **run:** @@ -43,7 +46,7 @@ The following environment variables can be set to change the behavior of dcgoss. #### DEBUG Enables debug output of `dcgoss`. - + When running in debug mode, the tmp dir with the container output will not be cleaned up. **Default:** empty @@ -54,7 +57,7 @@ When running in debug mode, the tmp dir with the container output will not be cl #### GOSS_PATH -Location of the goss binary to use. +Location of the goss binary to use. **Default:** `$(which goss)` @@ -104,8 +107,9 @@ If unset (or empty), the `--vars` flag is omitted, which is the normal behavior. #### GOSS_FILES_STRATEGY -Strategy used for copying goss files into the docker container. -If set to `'mount'` a volume with goss files is mounted and log output is streamed into the container as `/goss/docker_output.log` file. +Strategy used for copying goss files into the docker container. +If set to `'mount'` a volume with goss files is mounted and log output is streamed into the container as +`/goss/docker_output.log` file. Other strategy is `'cp'` which uses `'docker cp'` command to copy goss files into docker container. With the `'cp'` strategy you lose the ability to write tests or waits against the docker output. The `'cp'` strategy is required especially when docker daemon is not on the local machine. @@ -114,7 +118,8 @@ The `'cp'` strategy is required especially when docker daemon is not on the loca ## Debugging test runs -When debugging test execution its beneficual to set both `DEBUG=true` and `GOSS_WAIT_OPTS=-r 60s -s 5s` (without the redirect to `/dev/null`). +When debugging test execution its beneficual to set both `DEBUG=true` and `GOSS_WAIT_OPTS=-r 60s -s 5s` +(without the redirect to `/dev/null`). **Example:** diff --git a/extras/dgoss/README.md b/extras/dgoss/README.md index 324e850a2..ff88ed473 100644 --- a/extras/dgoss/README.md +++ b/extras/dgoss/README.md @@ -4,9 +4,11 @@ dgoss is a convenience wrapper around goss that aims to bring the simplicity of ## Examples and Tutorials -* [blog tutorial](https://medium.com/@aelsabbahy/tutorial-how-to-test-your-docker-image-in-half-a-second-bbd13e06a4a9) - Introduction to dgoss tutorial +* [blog tutorial](https://medium.com/@aelsabbahy/tutorial-how-to-test-your-docker-image-in-half-a-second-bbd13e06a4a9) - +Introduction to dgoss tutorial * [video tutorial](https://youtu.be/PEHz5EnZ-FM) - Same as above, but in video format -* [dgoss-examples](https://github.com/aelsabbahy/dgoss-examples) - Repo containing examples of using dgoss to validate docker images +* [dgoss-examples](https://github.com/aelsabbahy/dgoss-examples) - Repo containing examples of using dgoss to validate +docker images ## Installation @@ -43,7 +45,7 @@ dgoss run ... ### Run -Run is used to validate a docker container. +Run is used to validate a docker container. It expects a `./goss.yaml` file to exist in the directory it was invoked from. In most cases one can just substitute the docker command for the dgoss command, for example: @@ -65,7 +67,9 @@ In most cases one can just substitute the docker command for the dgoss command, ### Edit -Edit will launch a docker container, install goss, and drop the user into an interactive shell. Once the user quits the interactive shell, any `goss.yaml` or `goss_wait.yaml` are copied out into the current directory. This allows the user to leverage the `goss add|autoadd` commands to write tests as they would on a regular machine. +Edit will launch a docker container, install goss, and drop the user into an interactive shell. +Once the user quits the interactive shell, any `goss.yaml` or `goss_wait.yaml` are copied out into the current directory. +This allows the user to leverage the `goss add|autoadd` commands to write tests as they would on a regular machine. **Example:** @@ -121,12 +125,17 @@ If unset (or empty), the `--vars` flag is omitted, which is the normal behavior. #### GOSS_FILES_STRATEGY -Strategy used for copying goss files into the docker container. If set to `'mount'` a volume with goss files is mounted and log output is streamed into the container as `/goss/docker_output.log` file. Other strategy is `'cp'` which uses `'docker cp'` command to copy goss files into docker container. With the `'cp'` strategy you lose the ability to write tests or waits against the docker output. The `'cp'` strategy is required especially when docker daemon is not on the local machine. +Strategy used for copying goss files into the docker container. If set to `'mount'` a volume with goss files is mounted +and log output is streamed into the container as `/goss/docker_output.log` file. Other strategy is `'cp'` which uses +`'docker cp'` command to copy goss files into docker container. With the `'cp'` strategy you lose the ability to write +tests or waits against the docker output. The `'cp'` strategy is required especially when docker daemon is not on the +local machine. (Default `'mount'`) #### CONTAINER_LOG_OUTPUT -Location of the file that contains tested container logs. Logs are retained only if the variable is set to a non-empty string. (Default `''`) +Location of the file that contains tested container logs. Logs are retained only if the variable is set to a non-empty +string. (Default `''`) #### DGOSS_TEMP_DIR @@ -134,4 +143,5 @@ Location of the temporary directory used by dgoss. (Default `'$(mktemp -d /tmp/t #### CONTAINER_RUNTIME -Container runtime to use - `docker` or `podman`. Defaults to `docker`. Note that `podman` requires a run command to keep the container running. This defaults to `sleep infinity` in case only an image is passed to `dgoss` commands. \ No newline at end of file +Container runtime to use - `docker` or `podman`. Defaults to `docker`. Note that `podman` requires a run command to keep +the container running. This defaults to `sleep infinity` in case only an image is passed to `dgoss` commands. diff --git a/extras/kgoss/README.md b/extras/kgoss/README.md index ae3cbb047..daf14d34b 100644 --- a/extras/kgoss/README.md +++ b/extras/kgoss/README.md @@ -23,10 +23,10 @@ You can manually install kgoss and goss by going through the Web UI, getting the files and putting them in the right path. To get each of them: * **kgoss**: Run `curl -sSLO - https://raw.githubusercontent.com/goss-org/goss/master/extras/kgoss/kgoss`. + https://raw.githubusercontent.com/goss-org/goss/master/extras/kgoss/kgoss`. * **goss**: Download the `goss-linux-amd64` asset from and rename it `goss`. Place it - in your HOME directory, e.g. C:\\Users\\ on Windows; or set the + in your HOME directory, e.g. `C:\Users\` on Windows; or set the environment variable `GOSS_PATH` to its path. ### Automatic / CLI From 9729bc2b99f15a57b701b77961068360603b811e Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Tue, 21 May 2024 16:53:37 +0200 Subject: [PATCH 03/20] fix path pattern in documentation pipeline (#919) --- .github/workflows/docs.yaml | 2 +- .github/workflows/preview-docs.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 94ae98b6b..f7a871e6c 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -7,7 +7,7 @@ on: pull_request: paths: - mkdocs.yml - - docs/ + - docs/** - README.md - LICENSE - extras/**/README.md diff --git a/.github/workflows/preview-docs.yaml b/.github/workflows/preview-docs.yaml index e2aebafa7..37a47a597 100644 --- a/.github/workflows/preview-docs.yaml +++ b/.github/workflows/preview-docs.yaml @@ -5,7 +5,7 @@ on: - opened paths: - mkdocs.yml - - docs/ + - docs/** - README.md - LICENSE - extras/**/README.md From ebbbbc14281b7d832253e7c99d1d8086b210d3ab Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 May 2024 07:54:31 -0700 Subject: [PATCH 04/20] Bump mkdocs-material from 9.5.3 to 9.5.23 in /docs (#917) Bumps [mkdocs-material](https://github.com/squidfunk/mkdocs-material) from 9.5.3 to 9.5.23. - [Release notes](https://github.com/squidfunk/mkdocs-material/releases) - [Changelog](https://github.com/squidfunk/mkdocs-material/blob/master/CHANGELOG) - [Commits](https://github.com/squidfunk/mkdocs-material/compare/9.5.3...9.5.23) --- updated-dependencies: - dependency-name: mkdocs-material dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- docs/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 58910536a..af39529cd 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,4 +1,4 @@ -mkdocs-material==9.5.3 +mkdocs-material==9.5.23 mkdocs-macros-plugin==1.0.5 mkdocs-awesome-pages-plugin==2.9.2 mkdocs-exclude==1.0.2 From 784c3c296b7ab7f801e4933d8f397c50be8fae6b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 May 2024 07:54:46 -0700 Subject: [PATCH 05/20] Bump pygments from 2.17.2 to 2.18.0 in /docs (#918) Bumps [pygments](https://github.com/pygments/pygments) from 2.17.2 to 2.18.0. - [Release notes](https://github.com/pygments/pygments/releases) - [Changelog](https://github.com/pygments/pygments/blob/master/CHANGES) - [Commits](https://github.com/pygments/pygments/compare/2.17.2...2.18.0) --- updated-dependencies: - dependency-name: pygments dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- docs/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index af39529cd..7e1b447f5 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,4 +3,4 @@ mkdocs-macros-plugin==1.0.5 mkdocs-awesome-pages-plugin==2.9.2 mkdocs-exclude==1.0.2 mdx-breakless-lists==1.0.1 -pygments==2.17.2 +pygments==2.18.0 From 7ca545977ec1c9c9c3de6e612b92940940be849d Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Wed, 22 May 2024 23:02:48 +0200 Subject: [PATCH 06/20] Add github golang lint CI pipeline (#899) * Add github golang lint CI pipeline * add dependabot config * use go version from go.mod * run linter on linux only * restrict pipeline permissions --------- Co-authored-by: Ahmed Elsabbahy --- .github/dependabot.yml | 6 ++++++ .github/workflows/golangci-lint.yaml | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 .github/workflows/golangci-lint.yaml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 3e9267eda..5b773c6a8 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -13,6 +13,12 @@ updates: - "aelsabbahy" open-pull-requests-limit: 0 + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + day: "saturday" + - package-ecosystem: "pip" directory: "/docs" schedule: diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml new file mode 100644 index 000000000..9ec7ec636 --- /dev/null +++ b/.github/workflows/golangci-lint.yaml @@ -0,0 +1,27 @@ +name: Golang ci +on: + # don't build any branch other than master (and prs) when git pushed + pull_request: {} + push: + branches: + - master + - "/^v\\d+\\.\\d+(\\.\\d+)?(-\\S*)?$/" + +permissions: + contents: read + pull-requests: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: latest + only-new-issues: true From 855c3ce291ad667ea5116e747ccce7b73ea87708 Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Fri, 31 May 2024 18:45:13 +0200 Subject: [PATCH 07/20] bump alpine linux to 3.19 (#907) * bump alpine linux to 3.19 * set apk --no-cache --- integration-tests/Dockerfile_alpine3 | 4 ++-- integration-tests/goss/alpine3/goss-aa-expected.yaml | 2 +- integration-tests/goss/alpine3/goss-expected.yaml | 2 +- integration-tests/goss/vars.yaml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/integration-tests/Dockerfile_alpine3 b/integration-tests/Dockerfile_alpine3 index 153bc0c68..48713ceeb 100644 --- a/integration-tests/Dockerfile_alpine3 +++ b/integration-tests/Dockerfile_alpine3 @@ -1,9 +1,9 @@ -FROM alpine:3.12 +FROM alpine:3.19 MAINTAINER Ahmed # install apache2 and remove un-needed services RUN apk update && \ - apk add openrc apache2 bash ca-certificates tinyproxy && \ + apk add --no-cache openrc apache2=2.4.59-r0 bash ca-certificates tinyproxy && \ rc-update add apache2 && \ rc-update add tinyproxy && \ rm -rf /etc/init.d/networking /etc/init.d/hwdrivers /var/cache/apk/* /tmp/* diff --git a/integration-tests/goss/alpine3/goss-aa-expected.yaml b/integration-tests/goss/alpine3/goss-aa-expected.yaml index 2d95f3e6b..ea7c1180b 100644 --- a/integration-tests/goss/alpine3/goss-aa-expected.yaml +++ b/integration-tests/goss/alpine3/goss-aa-expected.yaml @@ -2,7 +2,7 @@ package: apache2: installed: true versions: - - 2.4.46-r1 + - 2.4.59-r0 service: apache2: enabled: true diff --git a/integration-tests/goss/alpine3/goss-expected.yaml b/integration-tests/goss/alpine3/goss-expected.yaml index 0953e91d8..b3fc9f83e 100644 --- a/integration-tests/goss/alpine3/goss-expected.yaml +++ b/integration-tests/goss/alpine3/goss-expected.yaml @@ -13,7 +13,7 @@ package: apache2: installed: true versions: - - 2.4.46-r1 + - 2.4.59-r0 foobar: installed: false vim-tiny: diff --git a/integration-tests/goss/vars.yaml b/integration-tests/goss/vars.yaml index cbf6df778..dd505182b 100644 --- a/integration-tests/goss/vars.yaml +++ b/integration-tests/goss/vars.yaml @@ -2,7 +2,7 @@ alpine3: proxy: http://127.0.0.1:8888 packages: - apache2: "2.4.46-r1" + apache2: "2.4.59-r0" services: apache2: [sysinit] arch: From 6a8fc9623d846e4b9093fde7f9685e6abcc21457 Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Fri, 7 Jun 2024 00:56:27 +0200 Subject: [PATCH 08/20] fix some linting failures and configure golangci-lint (#922) * fix some linting errors * add golangci-lint to Makefile * add gofmt to linters * add err to return values * fix some gosimple errors * remove unused code * fix fmt * replace golint with golangci-lint * fix some linting failures * revert error handling from cmd.Run() * fix more linting issues * fix http header in tests --- .github/workflows/golangci-lint.yaml | 3 +- .golangci.yaml | 16 +++++ Makefile | 4 +- cmd/goss/goss.go | 8 --- matchers/have_patterns.go | 8 --- matchers/type_conversion.go | 3 +- outputs/json.go | 3 +- outputs/junit.go | 3 +- outputs/nagios.go | 3 +- outputs/rspecish.go | 6 +- outputs/tap.go | 3 +- resource/addr.go | 4 +- resource/command.go | 2 +- resource/dns.go | 2 +- resource/file.go | 2 +- resource/group.go | 2 +- resource/http.go | 2 +- resource/interface.go | 2 +- resource/kernel_param.go | 2 +- resource/mount.go | 2 +- resource/package.go | 2 +- resource/port.go | 2 +- resource/process.go | 2 +- resource/resource.go | 14 ----- resource/resource_list.go | 90 ++++++++++++++-------------- resource/resource_list_genny.go | 6 +- resource/service.go | 2 +- resource/user.go | 2 +- resource/validate.go | 4 -- serve.go | 2 +- serve_test.go | 12 ++-- system/file.go | 7 +-- system/kernel_param.go | 3 +- system/service.go | 5 +- util/config.go | 4 +- 35 files changed, 104 insertions(+), 133 deletions(-) create mode 100644 .golangci.yaml diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml index 9ec7ec636..7bbb5cd9a 100644 --- a/.github/workflows/golangci-lint.yaml +++ b/.github/workflows/golangci-lint.yaml @@ -23,5 +23,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: latest - only-new-issues: true + version: v1.59 diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 000000000..52977cfd6 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,16 @@ +linters: + # Disable all linters. + # Default: false + disable-all: true + # Enable specific linter + # https://golangci-lint.run/usage/linters/#enabled-by-default + enable: + # default linter + # - errcheck # there are to many failures at the moment + - gosimple + - govet + - ineffassign + - staticcheck + - unused + # custom linter + - gofmt diff --git a/Makefile b/Makefile index 6d4cf159c..d45d21084 100644 --- a/Makefile +++ b/Makefile @@ -35,10 +35,10 @@ htmlcov: go test -v -coverpkg=./... -coverprofile=c.out ./... go tool cover -html ./c.out - lint: $(info INFO: Starting build $@) - golint $(pkgs) || true + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59 + golangci-lint run --timeout 5m $(pkgs) || true vet: $(info INFO: Starting build $@) diff --git a/cmd/goss/goss.go b/cmd/goss/goss.go index e7ff90540..0c6a061a2 100644 --- a/cmd/goss/goss.go +++ b/cmd/goss/goss.go @@ -423,14 +423,6 @@ func addAlphaFlagIfNeeded(app *cli.App) { } } -const msgFormat string = `WARNING: goss for this platform (%q) is alpha-quality, work-in-progress and community-supported. - -You should not expect everything to work. Treat linux as the canonical behaviour to expect. - -Please see https://github.com/goss-org/goss/tree/master/docs/platform-feature-parity.md to set your expectations and see progress. -Please file issues via https://github.com/goss-org/goss/issues/new/choose -Pull requests and bug reports very welcome.` - func fatalAlphaIfNeeded(c *cli.Context) { if runtime.GOOS == "darwin" || runtime.GOOS == "windows" { if c.GlobalString("use-alpha") != "1" { diff --git a/matchers/have_patterns.go b/matchers/have_patterns.go index fd7c92897..cf2bcd139 100644 --- a/matchers/have_patterns.go +++ b/matchers/have_patterns.go @@ -146,14 +146,6 @@ func (m *HavePatternsMatcher) NegatedFailureResult(actual interface{}) MatcherRe } } -func appendMissingStrings(message string, missingElements []string) string { - if len(missingElements) == 0 { - return message - } - return fmt.Sprintf("%s\nthe missing elements were\n%s", message, - format.Object(missingElements, 1)) -} - type patternMatcher interface { Match(string) bool Pattern() string diff --git a/matchers/type_conversion.go b/matchers/type_conversion.go index 0d425bb4f..29fb96db8 100644 --- a/matchers/type_conversion.go +++ b/matchers/type_conversion.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "strconv" "strings" @@ -108,7 +107,7 @@ func (t ReaderToString) Transform(i interface{}) (interface{}, error) { return nil, fmt.Errorf("Expected io.reader, Got:%s", format.Object(i, 1)) } - b, err := ioutil.ReadAll(r) + b, err := io.ReadAll(r) if err != nil { return "", err } diff --git a/outputs/json.go b/outputs/json.go index 0d7063d0c..c2413aaf4 100644 --- a/outputs/json.go +++ b/outputs/json.go @@ -24,8 +24,7 @@ func (r Json) ValidOptions() []*formatOption { func (r Json) Output(w io.Writer, results <-chan []resource.TestResult, outConfig util.OutputConfig) (exitCode int) { - var pretty bool - pretty = util.IsValueInList(foPretty, outConfig.FormatOptions) + var pretty bool = util.IsValueInList(foPretty, outConfig.FormatOptions) includeRaw := !util.IsValueInList(foExcludeRaw, outConfig.FormatOptions) sort := util.IsValueInList(foSort, outConfig.FormatOptions) diff --git a/outputs/junit.go b/outputs/junit.go index 3e7de6ead..d50e3677e 100644 --- a/outputs/junit.go +++ b/outputs/junit.go @@ -34,8 +34,7 @@ func (r JUnit) Output(w io.Writer, results <-chan []resource.TestResult, // ISO8601 timeformat timestamp := time.Now().Format(time.RFC3339) - var summary map[int]string - summary = make(map[int]string) + var summary map[int]string = make(map[int]string) var startTime time.Time var endTime time.Time diff --git a/outputs/nagios.go b/outputs/nagios.go index d91776dba..2940d2235 100644 --- a/outputs/nagios.go +++ b/outputs/nagios.go @@ -31,8 +31,7 @@ func (r Nagios) Output(w io.Writer, results <-chan []resource.TestResult, var startTime time.Time var endTime time.Time - var summary map[int]string - summary = make(map[int]string) + var summary map[int]string = make(map[int]string) for resultGroup := range results { for _, testResult := range resultGroup { diff --git a/outputs/rspecish.go b/outputs/rspecish.go index cdeae891f..7fb5f2f9f 100644 --- a/outputs/rspecish.go +++ b/outputs/rspecish.go @@ -43,15 +43,15 @@ func (r Rspecish) Output(w io.Writer, results <-chan []resource.TestResult, switch testResult.Result { case resource.SUCCESS: logTrace("TRACE", "SUCCESS", testResult, false) - fmt.Fprintf(w, green(".")) + fmt.Fprint(w, green(".")) case resource.SKIP: logTrace("TRACE", "SKIP", testResult, false) - fmt.Fprintf(w, yellow("S")) + fmt.Fprint(w, yellow("S")) failedOrSkippedGroup = append(failedOrSkippedGroup, testResult) skipped++ case resource.FAIL: logTrace("TRACE", "FAIL", testResult, false) - fmt.Fprintf(w, red("F")) + fmt.Fprint(w, red("F")) failedOrSkippedGroup = append(failedOrSkippedGroup, testResult) failed++ } diff --git a/outputs/tap.go b/outputs/tap.go index 341e2a0ef..a5d6166ca 100644 --- a/outputs/tap.go +++ b/outputs/tap.go @@ -27,8 +27,7 @@ func (r Tap) Output(w io.Writer, results <-chan []resource.TestResult, testCount := 0 failed := 0 - var summary map[int]string - summary = make(map[int]string) + var summary map[int]string = make(map[int]string) for resultGroup := range results { for _, testResult := range resultGroup { diff --git a/resource/addr.go b/resource/addr.go index 2347583e9..f98eb630f 100644 --- a/resource/addr.go +++ b/resource/addr.go @@ -20,6 +20,8 @@ type Addr struct { Skip bool `json:"skip,omitempty" yaml:"skip,omitempty"` } +type idKey struct{} + const ( AddrResourceKey = "addr" AddResourceName = "Addr" @@ -51,7 +53,7 @@ func (a *Addr) GetAddress() string { } func (a *Addr) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", a.ID()) + ctx := context.WithValue(context.Background(), idKey{}, a.ID()) skip := a.Skip if a.Timeout == 0 { diff --git a/resource/command.go b/resource/command.go index 79a1671e7..365867d24 100644 --- a/resource/command.go +++ b/resource/command.go @@ -49,7 +49,7 @@ func (c *Command) GetExec() string { } func (c *Command) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", c.ID()) + ctx := context.WithValue(context.Background(), idKey{}, c.ID()) skip := c.Skip if c.Timeout == 0 { diff --git a/resource/dns.go b/resource/dns.go index bd3274d99..6cd114002 100644 --- a/resource/dns.go +++ b/resource/dns.go @@ -52,7 +52,7 @@ func (d *DNS) GetResolve() string { } func (d *DNS) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", d.ID()) + ctx := context.WithValue(context.Background(), idKey{}, d.ID()) skip := d.Skip if d.Timeout == 0 { d.Timeout = 500 diff --git a/resource/file.go b/resource/file.go index 97356a193..6b3c94c4c 100644 --- a/resource/file.go +++ b/resource/file.go @@ -61,7 +61,7 @@ func (f *File) GetPath() string { } func (f *File) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", f.ID()) + ctx := context.WithValue(context.Background(), idKey{}, f.ID()) skip := f.Skip sysFile := sys.NewFile(ctx, f.GetPath(), sys, util.Config{}) diff --git a/resource/group.go b/resource/group.go index 7ca928108..cfd71a3a3 100644 --- a/resource/group.go +++ b/resource/group.go @@ -47,7 +47,7 @@ func (g *Group) GetGroupname() string { } func (g *Group) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", g.ID()) + ctx := context.WithValue(context.Background(), idKey{}, g.ID()) skip := g.Skip sysgroup := sys.NewGroup(ctx, g.GetGroupname(), sys, util.Config{}) diff --git a/resource/http.go b/resource/http.go index b9a1006de..bbd820098 100644 --- a/resource/http.go +++ b/resource/http.go @@ -63,7 +63,7 @@ func (r *HTTP) getURL() string { } func (u *HTTP) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", u.ID()) + ctx := context.WithValue(context.Background(), idKey{}, u.ID()) skip := u.Skip if u.Timeout == 0 { u.Timeout = 5000 diff --git a/resource/interface.go b/resource/interface.go index 14921d133..68e3fa3d6 100644 --- a/resource/interface.go +++ b/resource/interface.go @@ -50,7 +50,7 @@ func (i *Interface) GetName() string { } func (i *Interface) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", i.ID()) + ctx := context.WithValue(context.Background(), idKey{}, i.ID()) skip := i.Skip sysInterface := sys.NewInterface(ctx, i.GetName(), sys, util.Config{}) diff --git a/resource/kernel_param.go b/resource/kernel_param.go index 494597a96..7f50270bd 100644 --- a/resource/kernel_param.go +++ b/resource/kernel_param.go @@ -50,7 +50,7 @@ func (k *KernelParam) GetName() string { } func (k *KernelParam) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", k.ID()) + ctx := context.WithValue(context.Background(), idKey{}, k.ID()) skip := k.Skip sysKernelParam := sys.NewKernelParam(ctx, k.GetName(), sys, util.Config{}) diff --git a/resource/mount.go b/resource/mount.go index 401c172ec..4410cbb2f 100644 --- a/resource/mount.go +++ b/resource/mount.go @@ -54,7 +54,7 @@ func (m *Mount) GetMountPoint() string { } func (m *Mount) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", m.ID()) + ctx := context.WithValue(context.Background(), idKey{}, m.ID()) skip := m.Skip if m.Timeout == 0 { diff --git a/resource/package.go b/resource/package.go index f8afffcb5..6d393a1b2 100644 --- a/resource/package.go +++ b/resource/package.go @@ -47,7 +47,7 @@ func (p *Package) GetName() string { } func (p *Package) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", p.ID()) + ctx := context.WithValue(context.Background(), idKey{}, p.ID()) skip := p.Skip sysPkg := sys.NewPackage(ctx, p.GetName(), sys, util.Config{}) diff --git a/resource/port.go b/resource/port.go index 70f72ae93..02c32859c 100644 --- a/resource/port.go +++ b/resource/port.go @@ -47,7 +47,7 @@ func (p *Port) GetPort() string { } func (p *Port) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", p.ID()) + ctx := context.WithValue(context.Background(), idKey{}, p.ID()) skip := p.Skip sysPort := sys.NewPort(ctx, p.GetPort(), sys, util.Config{}) diff --git a/resource/process.go b/resource/process.go index 9012760e9..c7413d7ef 100644 --- a/resource/process.go +++ b/resource/process.go @@ -46,7 +46,7 @@ func (p *Process) GetComm() string { } func (p *Process) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", p.ID()) + ctx := context.WithValue(context.Background(), idKey{}, p.ID()) skip := p.Skip sysProcess := sys.NewProcess(ctx, p.GetComm(), sys, util.Config{}) diff --git a/resource/resource.go b/resource/resource.go index bff257e02..104972ad5 100644 --- a/resource/resource.go +++ b/resource/resource.go @@ -5,11 +5,9 @@ import ( "os" "path/filepath" "strconv" - "strings" "sync" "github.com/goss-org/goss/system" - "github.com/oleiade/reflections" ) type Resource interface { @@ -66,18 +64,6 @@ func deprecateAtoI(depr any, desc string) any { return float64(i) } -func validAttrs(i any, t string) (map[string]bool, error) { - validAttrs := make(map[string]bool) - tags, err := reflections.Tags(i, t) - if err != nil { - return nil, err - } - for _, v := range tags { - validAttrs[strings.Split(v, ",")[0]] = true - } - return validAttrs, nil -} - func shouldSkip(results []TestResult) bool { if len(results) < 1 { return false diff --git a/resource/resource_list.go b/resource/resource_list.go index e3aedb633..61b381596 100644 --- a/resource/resource_list.go +++ b/resource/resource_list.go @@ -18,7 +18,7 @@ import ( type AddrMap map[string]*Addr func (r AddrMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Addr, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewAddr(ctx, sr, sys, config) res, err := NewAddr(sysres, config) if err != nil { @@ -33,13 +33,13 @@ func (r AddrMap) AppendSysResource(sr string, sys *system.System, config util.Co } func (r AddrMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Addr, system.Addr, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewAddr(ctx, sr, sys, util.Config{}) res, err := NewAddr(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -119,7 +119,7 @@ func (ret *AddrMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type CommandMap map[string]*Command func (r CommandMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Command, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewCommand(ctx, sr, sys, config) res, err := NewCommand(sysres, config) if err != nil { @@ -134,13 +134,13 @@ func (r CommandMap) AppendSysResource(sr string, sys *system.System, config util } func (r CommandMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Command, system.Command, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewCommand(ctx, sr, sys, util.Config{}) res, err := NewCommand(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -220,7 +220,7 @@ func (ret *CommandMap) UnmarshalYAML(unmarshal func(v interface{}) error) error type DNSMap map[string]*DNS func (r DNSMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*DNS, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewDNS(ctx, sr, sys, config) res, err := NewDNS(sysres, config) if err != nil { @@ -235,13 +235,13 @@ func (r DNSMap) AppendSysResource(sr string, sys *system.System, config util.Con } func (r DNSMap) AppendSysResourceIfExists(sr string, sys *system.System) (*DNS, system.DNS, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewDNS(ctx, sr, sys, util.Config{}) res, err := NewDNS(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -321,7 +321,7 @@ func (ret *DNSMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type FileMap map[string]*File func (r FileMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*File, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewFile(ctx, sr, sys, config) res, err := NewFile(sysres, config) if err != nil { @@ -336,13 +336,13 @@ func (r FileMap) AppendSysResource(sr string, sys *system.System, config util.Co } func (r FileMap) AppendSysResourceIfExists(sr string, sys *system.System) (*File, system.File, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewFile(ctx, sr, sys, util.Config{}) res, err := NewFile(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -422,7 +422,7 @@ func (ret *FileMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type GossfileMap map[string]*Gossfile func (r GossfileMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Gossfile, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewGossfile(ctx, sr, sys, config) res, err := NewGossfile(sysres, config) if err != nil { @@ -437,13 +437,13 @@ func (r GossfileMap) AppendSysResource(sr string, sys *system.System, config uti } func (r GossfileMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Gossfile, system.Gossfile, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewGossfile(ctx, sr, sys, util.Config{}) res, err := NewGossfile(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -523,7 +523,7 @@ func (ret *GossfileMap) UnmarshalYAML(unmarshal func(v interface{}) error) error type GroupMap map[string]*Group func (r GroupMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Group, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewGroup(ctx, sr, sys, config) res, err := NewGroup(sysres, config) if err != nil { @@ -538,13 +538,13 @@ func (r GroupMap) AppendSysResource(sr string, sys *system.System, config util.C } func (r GroupMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Group, system.Group, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewGroup(ctx, sr, sys, util.Config{}) res, err := NewGroup(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -624,7 +624,7 @@ func (ret *GroupMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type PackageMap map[string]*Package func (r PackageMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Package, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewPackage(ctx, sr, sys, config) res, err := NewPackage(sysres, config) if err != nil { @@ -639,13 +639,13 @@ func (r PackageMap) AppendSysResource(sr string, sys *system.System, config util } func (r PackageMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Package, system.Package, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewPackage(ctx, sr, sys, util.Config{}) res, err := NewPackage(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -725,7 +725,7 @@ func (ret *PackageMap) UnmarshalYAML(unmarshal func(v interface{}) error) error type PortMap map[string]*Port func (r PortMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Port, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewPort(ctx, sr, sys, config) res, err := NewPort(sysres, config) if err != nil { @@ -740,13 +740,13 @@ func (r PortMap) AppendSysResource(sr string, sys *system.System, config util.Co } func (r PortMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Port, system.Port, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewPort(ctx, sr, sys, util.Config{}) res, err := NewPort(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -826,7 +826,7 @@ func (ret *PortMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type ProcessMap map[string]*Process func (r ProcessMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Process, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewProcess(ctx, sr, sys, config) res, err := NewProcess(sysres, config) if err != nil { @@ -841,13 +841,13 @@ func (r ProcessMap) AppendSysResource(sr string, sys *system.System, config util } func (r ProcessMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Process, system.Process, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewProcess(ctx, sr, sys, util.Config{}) res, err := NewProcess(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -927,7 +927,7 @@ func (ret *ProcessMap) UnmarshalYAML(unmarshal func(v interface{}) error) error type ServiceMap map[string]*Service func (r ServiceMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Service, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewService(ctx, sr, sys, config) res, err := NewService(sysres, config) if err != nil { @@ -942,13 +942,13 @@ func (r ServiceMap) AppendSysResource(sr string, sys *system.System, config util } func (r ServiceMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Service, system.Service, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewService(ctx, sr, sys, util.Config{}) res, err := NewService(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -1028,7 +1028,7 @@ func (ret *ServiceMap) UnmarshalYAML(unmarshal func(v interface{}) error) error type UserMap map[string]*User func (r UserMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*User, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewUser(ctx, sr, sys, config) res, err := NewUser(sysres, config) if err != nil { @@ -1043,13 +1043,13 @@ func (r UserMap) AppendSysResource(sr string, sys *system.System, config util.Co } func (r UserMap) AppendSysResourceIfExists(sr string, sys *system.System) (*User, system.User, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewUser(ctx, sr, sys, util.Config{}) res, err := NewUser(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -1129,7 +1129,7 @@ func (ret *UserMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type KernelParamMap map[string]*KernelParam func (r KernelParamMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*KernelParam, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewKernelParam(ctx, sr, sys, config) res, err := NewKernelParam(sysres, config) if err != nil { @@ -1144,13 +1144,13 @@ func (r KernelParamMap) AppendSysResource(sr string, sys *system.System, config } func (r KernelParamMap) AppendSysResourceIfExists(sr string, sys *system.System) (*KernelParam, system.KernelParam, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewKernelParam(ctx, sr, sys, util.Config{}) res, err := NewKernelParam(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -1230,7 +1230,7 @@ func (ret *KernelParamMap) UnmarshalYAML(unmarshal func(v interface{}) error) er type MountMap map[string]*Mount func (r MountMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Mount, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewMount(ctx, sr, sys, config) res, err := NewMount(sysres, config) if err != nil { @@ -1245,13 +1245,13 @@ func (r MountMap) AppendSysResource(sr string, sys *system.System, config util.C } func (r MountMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Mount, system.Mount, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewMount(ctx, sr, sys, util.Config{}) res, err := NewMount(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -1331,7 +1331,7 @@ func (ret *MountMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type InterfaceMap map[string]*Interface func (r InterfaceMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Interface, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewInterface(ctx, sr, sys, config) res, err := NewInterface(sysres, config) if err != nil { @@ -1346,13 +1346,13 @@ func (r InterfaceMap) AppendSysResource(sr string, sys *system.System, config ut } func (r InterfaceMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Interface, system.Interface, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewInterface(ctx, sr, sys, util.Config{}) res, err := NewInterface(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -1432,7 +1432,7 @@ func (ret *InterfaceMap) UnmarshalYAML(unmarshal func(v interface{}) error) erro type HTTPMap map[string]*HTTP func (r HTTPMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*HTTP, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewHTTP(ctx, sr, sys, config) res, err := NewHTTP(sysres, config) if err != nil { @@ -1447,13 +1447,13 @@ func (r HTTPMap) AppendSysResource(sr string, sys *system.System, config util.Co } func (r HTTPMap) AppendSysResourceIfExists(sr string, sys *system.System) (*HTTP, system.HTTP, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewHTTP(ctx, sr, sys, util.Config{}) res, err := NewHTTP(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { diff --git a/resource/resource_list_genny.go b/resource/resource_list_genny.go index a483bc4ea..fccdea348 100644 --- a/resource/resource_list_genny.go +++ b/resource/resource_list_genny.go @@ -26,7 +26,7 @@ type ResourceType generic.Type type ResourceTypeMap map[string]*ResourceType func (r ResourceTypeMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*ResourceType, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewResourceType(ctx, sr, sys, config) res, err := NewResourceType(sysres, config) if err != nil { @@ -41,13 +41,13 @@ func (r ResourceTypeMap) AppendSysResource(sr string, sys *system.System, config } func (r ResourceTypeMap) AppendSysResourceIfExists(sr string, sys *system.System) (*ResourceType, system.ResourceType, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewResourceType(ctx, sr, sys, util.Config{}) res, err := NewResourceType(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { diff --git a/resource/service.go b/resource/service.go index 2285c3e1f..2f35e9d3d 100644 --- a/resource/service.go +++ b/resource/service.go @@ -48,7 +48,7 @@ func (s *Service) GetName() string { } func (s *Service) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", s.ID()) + ctx := context.WithValue(context.Background(), idKey{}, s.ID()) skip := s.Skip sysservice := sys.NewService(ctx, s.GetName(), sys, util.Config{}) diff --git a/resource/user.go b/resource/user.go index 3895f8067..c1b64b06f 100644 --- a/resource/user.go +++ b/resource/user.go @@ -51,7 +51,7 @@ func (u *User) GetUsername() string { } func (u *User) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", u.ID()) + ctx := context.WithValue(context.Background(), idKey{}, u.ID()) skip := u.Skip sysuser := sys.NewUser(ctx, u.GetUsername(), sys, util.Config{}) diff --git a/resource/validate.go b/resource/validate.go index c7abb4428..720c7b7d5 100644 --- a/resource/validate.go +++ b/resource/validate.go @@ -41,10 +41,6 @@ func HumanOutcomes() map[int]string { return humanOutcomes } -const ( - maxScanTokenSize = 10 * 1024 * 1024 -) - type ValidateError string func (g ValidateError) Error() string { return string(g) } diff --git a/serve.go b/serve.go index 3adb34270..d30973adf 100644 --- a/serve.go +++ b/serve.go @@ -85,7 +85,7 @@ func (h healthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { log.Printf("[TRACE] %v: requesting health probe", r.RemoteAddr) resp := h.processAndEnsureCached(negotiatedContentType, outputer) - w.Header().Set(http.CanonicalHeaderKey("Content-Type"), negotiatedContentType) + w.Header().Set(http.CanonicalHeaderKey("Content-Type"), negotiatedContentType) //nolint:gosimple w.WriteHeader(resp.statusCode) logBody := "" if resp.statusCode != http.StatusOK { diff --git a/serve_test.go b/serve_test.go index b29fe3baf..8b19d048d 100644 --- a/serve_test.go +++ b/serve_test.go @@ -66,7 +66,7 @@ func TestServeWithNoContentNegotiation(t *testing.T) { t.Logf("testName %q log output:\n%s", testName, logOutput.String()) assert.Equal(t, tc.expectedHTTPStatus, rr.Code) if tc.expectedContentType != "" { - assert.Equal(t, []string{tc.expectedContentType}, rr.HeaderMap["Content-Type"]) + assert.Equal(t, tc.expectedContentType, rr.Result().Header.Get("Content-Type")) } }) } @@ -173,7 +173,7 @@ func TestServeNegotiatingContent(t *testing.T) { t.Logf("testName %q log output:\n%s", testName, logOutput.String()) assert.Equal(t, tc.expectedHTTPStatus, rr.Code) if tc.expectedContentType != "" { - assert.Equal(t, []string{tc.expectedContentType}, rr.HeaderMap["Content-Type"]) + assert.Equal(t, tc.expectedContentType, rr.Result().Header.Get("Content-Type")) } }) } @@ -297,11 +297,9 @@ func TestServeCacheNegotiatingContent(t *testing.T) { func makeRequest(t *testing.T, config *util.Config, headers map[string][]string) *http.Request { req, err := http.NewRequest("GET", config.Endpoint, nil) require.NoError(t, err) - if headers != nil { - for header, vals := range headers { - for _, v := range vals { - req.Header.Add(header, v) - } + for header, vals := range headers { + for _, v := range vals { + req.Header.Add(header, v) } } return req diff --git a/system/file.go b/system/file.go index 6927d910f..a6f1efaef 100644 --- a/system/file.go +++ b/system/file.go @@ -38,14 +38,13 @@ type hashFuncType string const ( md5Hash hashFuncType = "md5" - sha256Hash = "sha256" - sha512Hash = "sha512" + sha256Hash hashFuncType = "sha256" + sha512Hash hashFuncType = "sha512" ) type DefFile struct { path string realPath string - fi os.FileInfo loaded bool err error } @@ -167,7 +166,7 @@ func realPath(path string) (string, error) { if f == "~" { usr, err = user.Current() } else { - usr, err = user.Lookup(f[1:len(f)]) + usr, err = user.Lookup(f[1:]) } if err != nil { return "", err diff --git a/system/kernel_param.go b/system/kernel_param.go index 867e08f65..c7b6e29f8 100644 --- a/system/kernel_param.go +++ b/system/kernel_param.go @@ -14,8 +14,7 @@ type KernelParam interface { } type DefKernelParam struct { - key string - value string + key string } func NewDefKernelParam(_ context.Context, key string, system *System, config util.Config) KernelParam { diff --git a/system/service.go b/system/service.go index df2a43dc7..bdb280702 100644 --- a/system/service.go +++ b/system/service.go @@ -11,8 +11,5 @@ type Service interface { } func invalidService(s string) bool { - if strings.ContainsRune(s, '/') { - return true - } - return false + return strings.ContainsRune(s, '/') } diff --git a/util/config.go b/util/config.go index 8c0a68d19..3be5fa84e 100644 --- a/util/config.go +++ b/util/config.go @@ -271,7 +271,7 @@ func ValidateSections(unmarshal func(any) error, i any, whitelist map[string]boo typ := reflect.TypeOf(i) typs := strings.Split(typ.String(), ".")[1] for id, v := range toValidate { - for k, _ := range v { + for k := range v { if !whitelist[k] { return fmt.Errorf("invalid Attribute for %s:%s: %s", typs, id, k) } @@ -295,7 +295,7 @@ func WhitelistAttrs(i any, format format) (map[string]bool, error) { func IsValueInList(value string, list []string) bool { for _, v := range list { - if strings.ToLower(v) == strings.ToLower(value) { + if strings.EqualFold(v, value) { return true } } From a6451d2f8b7af34f56beafd43bb81091fb10e2ab Mon Sep 17 00:00:00 2001 From: Alexandre Espinosa Menor Date: Sat, 8 Jun 2024 23:20:02 +0200 Subject: [PATCH 09/20] =?UTF-8?q?regexFirstGroup=20return=20first=20group?= =?UTF-8?q?=20from=20regexp,=20useful=20with=20.env=20file=E2=80=A6=20(#89?= =?UTF-8?q?5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * regexFirstGroup return first group from regexp, useful with .env files and another config files * documentation about regexFirstGroup and example * modify func regexFirstGroup to findStringSubmatch, return all the submatchs from regex * func findStringSubmatch(), returns map[string]interface{} for use with get and named parenthesized subexpressions or stringfied array string --- docs/gossfile.md | 25 +++++++++++++++++++++++++ template.go | 39 +++++++++++++++++++++++++++++++++------ 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/docs/gossfile.md b/docs/gossfile.md index 31f259adf..0339b99fa 100644 --- a/docs/gossfile.md +++ b/docs/gossfile.md @@ -918,6 +918,31 @@ Available functions: `toUpper` : Changes piped input to UPPERCASE + + `findStringSubmatch regex string` + : Returns map[string]interface{} with the names of the parenthesized subexpressions, like `(?P[a-z])` + + {{ $regexDBrc := "\\'mysql:\\/\\/(?P[a-z0-9]+):(?P[a-z0-9]+)@localhost\\/(?Proundcube_[a-z0-9]+)\\';"}} + + {{ $rcConf := readFile /home/user/roundcube/config.inc.php | findStringSubmatch $regexDBrc }} + {{ $UserDBrc := get $rcConf "login" }} + {{ $PassDBrc := get $rcConf "password" }} + {{ $DBrc := get $rcConf "database" }} + + If not exists named parenthesized subexps, returns stringfied array string: + + {{ $regexDBrc := "\\'mysql:\\/\\/([a-z0-9]+):([a-z0-9]+)@localhost\\/(roundcube_[a-z0-9]+)\\';"}} + + {{ $rcConf := readFile /home/user/roundcube/config.inc.php | findStringSubmatch $regexDBrc }} + {{ $UserDBrc := get $rcConf "1" }} + {{ $PassDBrc := get $rcConf "2" }} + {{ $DBrc := get $rcConf "3" }} + + NOTE: stringfied string array begins with "1" ("0" is all the string matched) + + + + !!! warning gossfiles containing text/template `{{}}` controls will no longer work with `goss add/autoadd`. diff --git a/template.go b/template.go index 1d524eacd..8621ce9d4 100644 --- a/template.go +++ b/template.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "regexp" + "strconv" "strings" "text/template" @@ -76,11 +77,37 @@ func regexMatch(re, s string) (bool, error) { return compiled.MatchString(s), nil } +// return named parenthesized subexpresions, if received, or stringfied (Sprig "get" need strings) keys like array +func findStringSubmatch(pattern, input string) map[string]interface{} { + re := regexp.MustCompile(pattern) + els := re.FindStringSubmatch(input) + + elsMap := make(map[string]interface{}) + elsMapNamed := make(map[string]interface{}) + + // create always elsMaps but returns elsMapNamed if exists named parenthesized subexps + for i := 0; i < len(els); i++ { + // convert i to string according returned (https://github.com/goss-org/goss/pull/895#issuecomment-2075716706) + elsMap[strconv.Itoa(i)] = els[i] + + if re.SubexpNames()[i] != "" { + elsMapNamed[re.SubexpNames()[i]] = els[i] + } + } + + // returns elsMapNamed if exists named parenthesized subexps + if len(elsMapNamed) > 0 { + return elsMapNamed + } + return elsMap +} + var funcMap = template.FuncMap{ - "mkSlice": mkSlice, - "readFile": readFile, - "getEnv": getEnv, - "regexMatch": regexMatch, - "toUpper": strings.ToUpper, - "toLower": strings.ToLower, + "mkSlice": mkSlice, + "readFile": readFile, + "getEnv": getEnv, + "regexMatch": regexMatch, + "toUpper": strings.ToUpper, + "toLower": strings.ToLower, + "findStringSubmatch": findStringSubmatch, } From 05c2ceda75ccb5d4616c1b7e950540deaee81879 Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Sun, 16 Jun 2024 17:07:46 +0200 Subject: [PATCH 10/20] Update docs to fix linting issues (#930) --- docs/gossfile.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/docs/gossfile.md b/docs/gossfile.md index 0339b99fa..a463c2ceb 100644 --- a/docs/gossfile.md +++ b/docs/gossfile.md @@ -918,12 +918,11 @@ Available functions: `toUpper` : Changes piped input to UPPERCASE - `findStringSubmatch regex string` : Returns map[string]interface{} with the names of the parenthesized subexpressions, like `(?P[a-z])` - + {{ $regexDBrc := "\\'mysql:\\/\\/(?P[a-z0-9]+):(?P[a-z0-9]+)@localhost\\/(?Proundcube_[a-z0-9]+)\\';"}} - + {{ $rcConf := readFile /home/user/roundcube/config.inc.php | findStringSubmatch $regexDBrc }} {{ $UserDBrc := get $rcConf "login" }} {{ $PassDBrc := get $rcConf "password" }} @@ -932,7 +931,7 @@ Available functions: If not exists named parenthesized subexps, returns stringfied array string: {{ $regexDBrc := "\\'mysql:\\/\\/([a-z0-9]+):([a-z0-9]+)@localhost\\/(roundcube_[a-z0-9]+)\\';"}} - + {{ $rcConf := readFile /home/user/roundcube/config.inc.php | findStringSubmatch $regexDBrc }} {{ $UserDBrc := get $rcConf "1" }} {{ $PassDBrc := get $rcConf "2" }} @@ -940,9 +939,6 @@ Available functions: NOTE: stringfied string array begins with "1" ("0" is all the string matched) - - - !!! warning gossfiles containing text/template `{{}}` controls will no longer work with `goss add/autoadd`. From 424716b1de2d4c81a0a18dbdf8874ca13e10ac35 Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Sun, 16 Jun 2024 17:13:09 +0200 Subject: [PATCH 11/20] fix link to codeclimate in docs (#926) --- mkdocs.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mkdocs.yml b/mkdocs.yml index df2a127ff..b9fa16895 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -81,14 +81,14 @@ markdown_extensions: check_paths: true - pymdownx.superfences -copyright: Copyright © 2015 - 2023 Ahmed Elsabbahy +copyright: Copyright © 2015 - 2024 Ahmed Elsabbahy extra: social: - icon: fontawesome/brands/github - link: https://github.com/gooss-org/goss + link: https://github.com/goss-org/goss - icon: simple/codeclimate - link: https://codeclimate.com/github/goss-org/goss + link: https://codeclimate.com/github/aelsabbahy/goss - icon: simple/travisci link: https://travis-ci.org/goss-org/goss - icon: fontawesome/brands/medium From 2be65b4481c706000228736deba323f81bd70a07 Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Sun, 16 Jun 2024 17:28:02 +0200 Subject: [PATCH 12/20] disable deprecated codeclimate plugin golint (#927) --- .codeclimate.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index ea45cf1d1..9b2d71710 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -6,8 +6,6 @@ checks: plugins: gofmt: enabled: true - golint: - enabled: true govet: enabled: true From 3a6435f39cc2e8d6924cb107a28d88c7ce0c5238 Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Fri, 21 Jun 2024 17:40:56 +0200 Subject: [PATCH 13/20] fix integration tests for alpine3 (#937) --- integration-tests/Dockerfile_alpine3 | 1 + 1 file changed, 1 insertion(+) diff --git a/integration-tests/Dockerfile_alpine3 b/integration-tests/Dockerfile_alpine3 index 48713ceeb..c573021ee 100644 --- a/integration-tests/Dockerfile_alpine3 +++ b/integration-tests/Dockerfile_alpine3 @@ -4,6 +4,7 @@ MAINTAINER Ahmed # install apache2 and remove un-needed services RUN apk update && \ apk add --no-cache openrc apache2=2.4.59-r0 bash ca-certificates tinyproxy && \ + sed -i 's/Listen 80/Listen 0.0.0.0:80/g' /etc/apache2/httpd.conf && \ rc-update add apache2 && \ rc-update add tinyproxy && \ rm -rf /etc/init.d/networking /etc/init.d/hwdrivers /var/cache/apk/* /tmp/* From 99db7abc36f6b62b794cfe9077f043ac765875e8 Mon Sep 17 00:00:00 2001 From: Ahmed Elsabbahy Date: Fri, 21 Jun 2024 11:41:56 -0700 Subject: [PATCH 14/20] Pushed new integration test images and update image md5 (#938) --- integration-tests/Dockerfile_alpine3.md5 | 2 +- integration-tests/Dockerfile_trusty.md5 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/integration-tests/Dockerfile_alpine3.md5 b/integration-tests/Dockerfile_alpine3.md5 index 0526fed52..f4bdce743 100644 --- a/integration-tests/Dockerfile_alpine3.md5 +++ b/integration-tests/Dockerfile_alpine3.md5 @@ -1 +1 @@ -f2b97c4629a92aa7f9b378b49f6e1b42 Dockerfile_alpine3 +f9c8c187e94693c4625a8c8d01fae3bf Dockerfile_alpine3 diff --git a/integration-tests/Dockerfile_trusty.md5 b/integration-tests/Dockerfile_trusty.md5 index 7e049058a..5a2c288f6 100644 --- a/integration-tests/Dockerfile_trusty.md5 +++ b/integration-tests/Dockerfile_trusty.md5 @@ -1 +1 @@ -5117819dc7907aa1100e2ff0f2edb68f Dockerfile_trusty +ac8c8df3415c0eecdbedc322480e696e Dockerfile_trusty From bdc4f154db2828bb6fdc7cc278e6ada9a4375d94 Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Mon, 24 Jun 2024 15:36:15 +0200 Subject: [PATCH 15/20] Add pipeline for build goss docker image (#909) * Add pipeline for build goss docker image * use go version from project * adapt setting version to changed var from PR #892 * add docs --- .github/workflows/docker-goss.yaml | 98 ++++++++++++++++++++++++++++++ Dockerfile | 19 ++++++ README.md | 4 ++ docs/.pages | 1 + docs/container_image.md | 53 ++++++++++++++++ 5 files changed, 175 insertions(+) create mode 100644 .github/workflows/docker-goss.yaml create mode 100644 Dockerfile create mode 100644 docs/container_image.md diff --git a/.github/workflows/docker-goss.yaml b/.github/workflows/docker-goss.yaml new file mode 100644 index 000000000..78e07bdcd --- /dev/null +++ b/.github/workflows/docker-goss.yaml @@ -0,0 +1,98 @@ +name: Docker image for Goss + +on: + push: + branches: + - master + tags: + - "v*" + workflow_dispatch: + +env: + PLATFORMS: "linux/amd64,linux/arm64" + +jobs: + goss: + name: Build and push Docker image + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + security-events: write # To upload Trivy sarif files + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ghcr.io/${{ github.repository_owner }}/goss + + - name: Get latest git tag + uses: actions-ecosystem/action-get-latest-tag@v1 + id: get-latest-tag + + - name: Set short git commit SHA + run: | + calculatedSha=$(git rev-parse --short ${{ github.sha }}) + echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV + + - name: Get the current version of Go from project. + run: echo "GO_VERSION_FROM_PROJECT=$(go mod edit -json | jq -r .Go)" >> $GITHUB_ENV + + - name: Build master goss image + if: github.ref_name == 'master' + uses: docker/build-push-action@v5 + with: + build-args: | + GO_VERSION=${{ env.GO_VERSION_FROM_PROJECT }} + GOSS_VERSION=${{ steps.get-latest-tag.outputs.tag }}-${{ github.ref_name }}+${{ env.COMMIT_SHORT_SHA }} + context: . + push: true + tags: | + ghcr.io/${{ github.repository_owner }}/goss:master + labels: ${{ steps.meta.outputs.labels }} + platforms: ${{ env.PLATFORMS }} + + - name: Build release goss image + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') + uses: docker/build-push-action@v5 + with: + build-args: | + GO_VERSION=${{ env.GO_VERSION_FROM_PROJECT }} + GOSS_VERSION=${{ github.ref_name }} + context: . + push: true + tags: | + ghcr.io/${{ github.repository_owner }}/goss:latest + ghcr.io/${{ github.repository_owner }}/goss:${{ github.ref_name }} + labels: ${{ steps.meta.outputs.labels }} + platforms: ${{ env.PLATFORMS }} + + - name: Run Trivy vulnerability scanner + uses: aquasecurity/trivy-action@master + with: + image-ref: ghcr.io/${{ github.repository_owner }}/goss:master + format: "sarif" + output: "trivy-results.sarif" + + - name: Upload Trivy scan results to GitHub Security tab + uses: github/codeql-action/upload-sarif@v3 + with: + sarif_file: "trivy-results.sarif" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..93a143a3d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +ARG GO_VERSION=1.21 + +FROM docker.io/golang:${GO_VERSION}-alpine AS base + +ARG GOSS_VERSION=v0.0.0 +WORKDIR /build + +RUN --mount=target=. \ + CGO_ENABLED=0 go build \ + -ldflags "-X github.com/goss-org/goss/util.Version=${GOSS_VERSION} -s -w" \ + -o "/release/goss" \ + ./cmd/goss + +FROM alpine:3.19 + +COPY --from=base /release/* /usr/bin/ + +RUN mkdir /goss +VOLUME /goss diff --git a/README.md b/README.md index 02ede20cb..c1788885c 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,10 @@ make build [Full Documentation](https://github.com/goss-org/goss/blob/e73553f9c3065ac297499dafb4f8abef6acb24ad/docs/manual.md) +## Using the container image + +[Using the Goss container image](docs/container_image.md) + ## Quick start diff --git a/docs/.pages b/docs/.pages index 67373453b..bed10fe4c 100644 --- a/docs/.pages +++ b/docs/.pages @@ -2,6 +2,7 @@ nav: - Home: index.md - installation.md - quickstart.md + - container_image.md - Command Reference: cli.md - The gossfile: gossfile.md - migrations.md diff --git a/docs/container_image.md b/docs/container_image.md new file mode 100644 index 000000000..ba12d30f7 --- /dev/null +++ b/docs/container_image.md @@ -0,0 +1,53 @@ +# Goss container image + +## Dockerfiles + +* [latest](https://github.com/goss-org/goss/blob/master/Dockerfile) + +## Using the base image + +This is a simple alpine image with Goss preinstalled on it. +Can be used as a base image for your projects to allow for easy health checking. + +### Mount example + +Create the container + +```sh +docker run --name goss ghcr.io/goss-org/goss goss +``` + +Create your container and mount goss + +```sh +docker run --rm -it --volumes-from goss --name weby nginx +``` + +Run goss inside your container + +```sh +docker exec weby /goss/goss autoadd nginx +``` + +### HEALTHCHECK example + +```dockerfile +FROM ghcr.io/goss-org/goss:latest + +COPY goss/ /goss/ +HEALTHCHECK --interval=1s --timeout=6s CMD goss -g /goss/goss.yaml validate + +# your stuff.. +``` + +### Startup delay example + +```dockerfile +FROM ghcr.io/goss-org/goss:latest + +COPY goss/ /goss/ + +# Alternatively, the -r option can be set +# using the GOSS_RETRY_TIMEOUT env variable +CMD goss -g /goss/goss.yaml validate -r 5m && exec real_comand.. +``` From 49e0171f61bde0323e110c1e48eee70f66b9ff18 Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Wed, 3 Jul 2024 16:59:26 +0200 Subject: [PATCH 16/20] add unit tests to ci (#928) --- .../{golangci-lint.yaml => golangci.yaml} | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) rename .github/workflows/{golangci-lint.yaml => golangci.yaml} (64%) diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci.yaml similarity index 64% rename from .github/workflows/golangci-lint.yaml rename to .github/workflows/golangci.yaml index 7bbb5cd9a..dde4b4d41 100644 --- a/.github/workflows/golangci-lint.yaml +++ b/.github/workflows/golangci.yaml @@ -6,13 +6,15 @@ on: branches: - master - "/^v\\d+\\.\\d+(\\.\\d+)?(-\\S*)?$/" + paths-ignore: + - "**/*.md" permissions: contents: read pull-requests: read jobs: - golangci: + lint: name: lint runs-on: ubuntu-latest steps: @@ -20,7 +22,20 @@ jobs: - uses: actions/setup-go@v5 with: go-version-file: go.mod + - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: version: v1.59 + + coverage: + name: coverage + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Unit tests and coverage + run: make cov From c9e7b54123d006f59be8a8560ec71c39a320d9de Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Wed, 3 Jul 2024 17:05:38 +0200 Subject: [PATCH 17/20] remove Code Climate from project (#933) * remove Code Climate from project * remove global token --- .codeclimate.yml | 15 --------------- .travis.yml | 13 ------------- ci/after-build.sh | 8 -------- ci/before-build.sh | 8 -------- ci/install.sh | 11 ----------- mkdocs.yml | 2 -- 6 files changed, 57 deletions(-) delete mode 100644 .codeclimate.yml delete mode 100755 ci/after-build.sh delete mode 100755 ci/before-build.sh delete mode 100755 ci/install.sh diff --git a/.codeclimate.yml b/.codeclimate.yml deleted file mode 100644 index 9b2d71710..000000000 --- a/.codeclimate.yml +++ /dev/null @@ -1,15 +0,0 @@ -version: "2" -checks: - return-statements: - config: - threshold: 6 -plugins: - gofmt: - enabled: true - govet: - enabled: true - -exclude_patterns: - - "!**/**.go" - - "**/*_test.go" - - "resource/resource_list.go" diff --git a/.travis.yml b/.travis.yml index 7d1886919..f18455cba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,4 @@ --- -env: - global: - - secure: IH/xOtRl9rcek+YTz1s2lv2njdV1gob0AY21/kGhqUBH2sdztQ/02CteGz5E0c+LfqoUYQglLsejVCNLXQJI39CyZRzysB1wlVOz7YIPNaOLATtMGg0/8Mb7dpeqAV1u3agIi87q3ims1EkmGE9UGNj/qL75oTXBiozEfkbcsheH3Ju9CcO0i006UlNqAG4T++l1JZ4kPmr1r5eNjRu52oWQrlxaOYpZJGnT3qjxkvxcnI/Pgiem0+2aZ7Yluu0lA7UCFWyORoDRUz4pQR3uDG4ADPG4WcpJ601LDZyWtS7EOXVBgWZX9vV9ZVx63nK5w0W8NN6PQOuz0niN9iwR+FsShrPIsh6P9wVZfGifwXK4g2FL2XMBRuZCsQfrpRY6JbnuyGeMqN53ta95y0Yv4H65UQ7bulr4Lnic4+W52G/fl1VUYX8Bts+ecUydIu+afcDZ6GkpVLEURjaek99uO5ewHH7lfVAOQv4wUP8GFUyLXJumJZHvMzyiAXsTHdUZdm+Ap8EPzWFYYnMxySU39MEkIvhfG47X6sA7zAppuoNwd8vU4ZaxSdsme2InUSalETGJZ7ohL+M/tkTMyuyq8uLMRuwscNdgcCjGaHM19NQMrv4nsPmmzTeiDRoFk2wad07Mgsjy07esxw52rs3zAsa37+h74GYFWYo523AiYjw= - language: go go: @@ -31,18 +27,9 @@ before_install: # bash from macOS is too old to have readarray. Install newer version. - if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then HOMEBREW_NO_AUTO_UPDATE=1 brew install bash; fi -install: - - ./ci/install.sh - -before_script: - - ./ci/before-build.sh - script: - ./ci/build.sh -after_script: - - ./ci/after-build.sh - deploy: provider: releases api_key: diff --git a/ci/after-build.sh b/ci/after-build.sh deleted file mode 100755 index 8970a6375..000000000 --- a/ci/after-build.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -os_name="$(go env GOOS)" - -if [[ "${os_name}" != "windows" ]]; then - ./cc-test-reporter after-build --exit-code "${TRAVIS_TEST_RESULT}" -d -fi diff --git a/ci/before-build.sh b/ci/before-build.sh deleted file mode 100755 index 0c5475d4f..000000000 --- a/ci/before-build.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -os_name="$(go env GOOS)" - -if [[ "${os_name}" != "windows" ]]; then - ./cc-test-reporter before-build -fi diff --git a/ci/install.sh b/ci/install.sh deleted file mode 100755 index 8dea0dab3..000000000 --- a/ci/install.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -os_name="$(go env GOOS)" - -go get -u golang.org/x/lint/golint - -if [[ "${os_name}" != "windows" ]]; then - curl -L "https://codeclimate.com/downloads/test-reporter/test-reporter-latest-${os_name}-amd64" > "./cc-test-reporter" - chmod +x "./cc-test-reporter" -fi diff --git a/mkdocs.yml b/mkdocs.yml index b9fa16895..7156db5e6 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -87,8 +87,6 @@ extra: social: - icon: fontawesome/brands/github link: https://github.com/goss-org/goss - - icon: simple/codeclimate - link: https://codeclimate.com/github/aelsabbahy/goss - icon: simple/travisci link: https://travis-ci.org/goss-org/goss - icon: fontawesome/brands/medium From b8ff782fb12f10974f5e8692e66a0334c681b69e Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Wed, 3 Jul 2024 19:24:02 +0200 Subject: [PATCH 18/20] docs: Update and more general wording for "docker container" (#934) * docs: Update and more general wording for "docker container" * revert one change * revert one change at README.md * revert changes at dcgoss * revert again --- README.md | 2 +- extras/dgoss/README.md | 23 ++++++++++++----------- extras/kgoss/README.md | 4 ++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c1788885c..cc5d40434 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ asciicast -**Note:** For testing docker containers see the [dgoss](https://github.com/goss-org/goss/tree/master/extras/dgoss) wrapper. +**Note:** For testing containers see the [dgoss](https://github.com/goss-org/goss/tree/master/extras/dgoss) wrapper. Also, user submitted wrapper scripts for Kubernetes [kgoss](https://github.com/goss-org/goss/tree/master/extras/kgoss) and Docker Compose [dcgoss](https://github.com/goss-org/goss/tree/master/extras/dcgoss). diff --git a/extras/dgoss/README.md b/extras/dgoss/README.md index ff88ed473..ebe7fd3fd 100644 --- a/extras/dgoss/README.md +++ b/extras/dgoss/README.md @@ -1,6 +1,6 @@ # dgoss -dgoss is a convenience wrapper around goss that aims to bring the simplicity of goss to docker containers. +dgoss is a convenience wrapper around goss that aims to bring the simplicity of goss to containers. ## Examples and Tutorials @@ -8,7 +8,7 @@ dgoss is a convenience wrapper around goss that aims to bring the simplicity of Introduction to dgoss tutorial * [video tutorial](https://youtu.be/PEHz5EnZ-FM) - Same as above, but in video format * [dgoss-examples](https://github.com/aelsabbahy/dgoss-examples) - Repo containing examples of using dgoss to validate -docker images +container images ## Installation @@ -45,9 +45,10 @@ dgoss run ... ### Run -Run is used to validate a docker container. +Run is used to validate a container. It expects a `./goss.yaml` file to exist in the directory it was invoked from. -In most cases one can just substitute the docker command for the dgoss command, for example: +In most cases one can just substitute the runtime command (`docker` or `podman`) +for the dgoss command, for example: **run:** @@ -61,13 +62,13 @@ In most cases one can just substitute the docker command for the dgoss command, * Run the container with the flags you specified. * Stream the containers log output into the container as `/goss/docker_output.log` - * This allows writing tests or waits against the docker output + * This allows writing tests or waits against the container output * (optional) Run `goss` with `$GOSS_WAIT_OPTS` if `./goss_wait.yaml` file exists in the current dir * Run `goss` with `$GOSS_OPTS` using `./goss.yaml` ### Edit -Edit will launch a docker container, install goss, and drop the user into an interactive shell. +Edit will launch a container, install goss, and drop the user into an interactive shell. Once the user quits the interactive shell, any `goss.yaml` or `goss_wait.yaml` are copied out into the current directory. This allows the user to leverage the `goss add|autoadd` commands to write tests as they would on a regular machine. @@ -117,18 +118,18 @@ directory `DGOSS_TEMP_DIR`. (Default: `''`) #### GOSS_VARS The name of the variables file relative to `GOSS_FILES_PATH` to copy into the -docker container and use for valiation (i.e. `dgoss run`) and copy out of the -docker container when writing tests (i.e. `dgoss edit`). If set, the +container and use for valiation (i.e. `dgoss run`) and copy out of the +container when writing tests (i.e. `dgoss edit`). If set, the `--vars` flag is passed to `goss validate` commands inside the container. If unset (or empty), the `--vars` flag is omitted, which is the normal behavior. (Default: `''`). #### GOSS_FILES_STRATEGY -Strategy used for copying goss files into the docker container. If set to `'mount'` a volume with goss files is mounted +Strategy used for copying goss files into the container. If set to `'mount'` a volume with goss files is mounted and log output is streamed into the container as `/goss/docker_output.log` file. Other strategy is `'cp'` which uses -`'docker cp'` command to copy goss files into docker container. With the `'cp'` strategy you lose the ability to write -tests or waits against the docker output. The `'cp'` strategy is required especially when docker daemon is not on the +`'docker cp'` command to copy goss files into container. With the `'cp'` strategy you lose the ability to write +tests or waits against the container output. The `'cp'` strategy is required especially when container daemon is not on the local machine. (Default `'mount'`) diff --git a/extras/kgoss/README.md b/extras/kgoss/README.md index daf14d34b..eb9f14d47 100644 --- a/extras/kgoss/README.md +++ b/extras/kgoss/README.md @@ -96,7 +96,7 @@ To find `goss.yaml` in another directory specify that directory's path in `GOSS_ ### Run -The `run` command is used to validate a docker container. It expects a +The `run` command is used to validate a container. It expects a `./goss.yaml` file to exist in the directory it was invoked from. **Example:** @@ -111,7 +111,7 @@ The `run` command is used to validate a docker container. It expects a ### Edit -Edit will launch a docker container, install goss, and drop the user into an +Edit will launch a container, install goss, and drop the user into an interactive shell. Once the user quits the interactive shell, any `goss.yaml` or `goss_wait.yaml` are copied out into the current directory. This allows the user to leverage the `goss add|autoadd` commands to write tests as they would From ff267843ddd4bcd97281f59720298b73fecfa799 Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Tue, 9 Jul 2024 02:46:59 +0200 Subject: [PATCH 19/20] ci: add integation tests to GHA CI (#946) --- .github/workflows/golangci.yaml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/golangci.yaml b/.github/workflows/golangci.yaml index dde4b4d41..c9cad6e74 100644 --- a/.github/workflows/golangci.yaml +++ b/.github/workflows/golangci.yaml @@ -29,6 +29,7 @@ jobs: version: v1.59 coverage: + needs: [lint] name: coverage runs-on: ubuntu-latest steps: @@ -39,3 +40,22 @@ jobs: - name: Unit tests and coverage run: make cov + + integartion-test: + needs: [coverage] + name: Integration tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + #- name: Integration tests + # run: make test-int-all + + # GHA does not work with centos7 + - name: Integration tests-64 + run: make wheezy trusty alpine3 arch test-int-serve-linux-amd64 + - name: Integration tests-32 + run: make wheezy-32 trusty-32 alpine3-32 arch-32 From 05f03a36ef6575b12e85670f3430a5e6e55dd547 Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Tue, 9 Jul 2024 15:20:10 +0200 Subject: [PATCH 20/20] Replace centos7 with rockylinux9 in integration-tests (#906) * add rockylinux9 test image * use own .PHONY directive to avoid merge conflicts * replace centos7 with rockylinux9 in integration tests --------- Co-authored-by: Ahmed Elsabbahy --- .github/workflows/golangci.yaml | 10 +- Makefile | 12 +- integration-tests/Dockerfile_rockylinux9 | 25 +++ integration-tests/goss/generate_goss.sh | 4 +- integration-tests/goss/goss-service.yaml | 2 +- .../goss/rockylinux9/goss-aa-expected.yaml | 17 ++ .../goss/rockylinux9/goss-expected-q.yaml | 127 +++++++++++++ .../goss/rockylinux9/goss-expected.yaml | 177 ++++++++++++++++++ integration-tests/goss/rockylinux9/goss.yaml | 33 ++++ integration-tests/goss/vars.yaml | 6 + integration-tests/test.sh | 4 +- 11 files changed, 402 insertions(+), 15 deletions(-) create mode 100644 integration-tests/Dockerfile_rockylinux9 create mode 100644 integration-tests/goss/rockylinux9/goss-aa-expected.yaml create mode 100644 integration-tests/goss/rockylinux9/goss-expected-q.yaml create mode 100644 integration-tests/goss/rockylinux9/goss-expected.yaml create mode 100644 integration-tests/goss/rockylinux9/goss.yaml diff --git a/.github/workflows/golangci.yaml b/.github/workflows/golangci.yaml index c9cad6e74..c04a58a99 100644 --- a/.github/workflows/golangci.yaml +++ b/.github/workflows/golangci.yaml @@ -51,11 +51,5 @@ jobs: with: go-version-file: go.mod - #- name: Integration tests - # run: make test-int-all - - # GHA does not work with centos7 - - name: Integration tests-64 - run: make wheezy trusty alpine3 arch test-int-serve-linux-amd64 - - name: Integration tests-32 - run: make wheezy-32 trusty-32 alpine3-32 arch-32 + - name: Integration tests + run: make test-int-all diff --git a/Makefile b/Makefile index d45d21084..b5148e82f 100644 --- a/Makefile +++ b/Makefile @@ -96,8 +96,8 @@ test-darwin-all: test-short-all test-int-darwin-all test-linux-all: test-short-all test-int-64 test-int-32 test-windows-all: test-short-all test-int-windows-all -test-int-64: centos7 wheezy trusty alpine3 arch test-int-serve-linux-amd64 -test-int-32: centos7-32 wheezy-32 trusty-32 alpine3-32 arch-32 +test-int-64: rockylinux9 wheezy trusty alpine3 arch test-int-serve-linux-amd64 +test-int-32: rockylinux9-32 wheezy-32 trusty-32 alpine3-32 arch-32 test-int-darwin-all: test-int-validate-darwin-amd64 test-int-serve-darwin-amd64 test-int-windows-all: test-int-validate-windows-amd64 test-int-serve-windows-amd64 test-int-all: test-int-32 test-int-64 @@ -105,6 +105,10 @@ test-int-all: test-int-32 test-int-64 centos7-32: build $(info INFO: Starting build $@) cd integration-tests/ && ./test.sh centos7 386 +.PHONY: rockylinux9-32 +rockylinux9-32: build + $(info INFO: Starting build $@) + cd integration-tests/ && ./test.sh rockylinux9 386 wheezy-32: build $(info INFO: Starting build $@) cd integration-tests/ && ./test.sh wheezy 386 @@ -120,6 +124,10 @@ arch-32: build centos7: build $(info INFO: Starting build $@) cd integration-tests/ && ./test.sh centos7 amd64 +.PHONY: rockylinux9 +rockylinux9: build + $(info INFO: Starting build $@) + cd integration-tests/ && ./test.sh rockylinux9 amd64 wheezy: build $(info INFO: Starting build $@) cd integration-tests/ && ./test.sh wheezy amd64 diff --git a/integration-tests/Dockerfile_rockylinux9 b/integration-tests/Dockerfile_rockylinux9 new file mode 100644 index 000000000..5416e89b0 --- /dev/null +++ b/integration-tests/Dockerfile_rockylinux9 @@ -0,0 +1,25 @@ +FROM rockylinux:9 + +ENV container docker + +RUN dnf install -y systemd httpd diffutils 'dnf-command(config-manager)' && \ + dnf config-manager --set-enabled crb && \ + dnf install -y epel-release && \ + dnf install -y tinyproxy && \ + dnf remove -y 'dnf-command(config-manager)' epel-release + +RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \ + rm -f /lib/systemd/system/multi-user.target.wants/*;\ + rm -f /etc/systemd/system/*.wants/*;\ + rm -f /lib/systemd/system/local-fs.target.wants/*; \ + rm -f /lib/systemd/system/sockets.target.wants/*udev*; \ + rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \ + rm -f /lib/systemd/system/basic.target.wants/*;\ + rm -f /lib/systemd/system/anaconda.target.wants/*; + +CMD ["/usr/sbin/init"] + +RUN systemctl enable httpd +RUN systemctl enable tinyproxy +RUN chmod 700 ~root +RUN mkfifo /pipe diff --git a/integration-tests/goss/generate_goss.sh b/integration-tests/goss/generate_goss.sh index e07cb28d5..096bfa89d 100755 --- a/integration-tests/goss/generate_goss.sh +++ b/integration-tests/goss/generate_goss.sh @@ -18,8 +18,8 @@ for x in /etc/passwd /tmp/goss/foobar;do goss a "${args[@]}" file $x done -[[ $OS == "centos7" ]] && package="httpd" || package="apache2" -[[ $OS == "centos7" ]] && user="apache" || user="www-data" +[[ $OS == "centos7" || $OS == "rockylinux9" ]] && package="httpd" || package="apache2" +[[ $OS == "centos7" || $OS == "rockylinux9" ]] && user="apache" || user="www-data" goss a "${args[@]}" package $package foobar vim-tiny goss a "${args[@]}" addr --timeout 1s httpbin:80 httpbin:22 diff --git a/integration-tests/goss/goss-service.yaml b/integration-tests/goss/goss-service.yaml index 102c92cbf..08633b078 100644 --- a/integration-tests/goss/goss-service.yaml +++ b/integration-tests/goss/goss-service.yaml @@ -3,7 +3,7 @@ service: foobar: enabled: false running: false -{{ if .Env.OS | regexMatch "centos[7]" }} +{{ if .Env.OS | regexMatch "centos[7]|rockylinux[9]" }} httpd: {{else}} apache2: diff --git a/integration-tests/goss/rockylinux9/goss-aa-expected.yaml b/integration-tests/goss/rockylinux9/goss-aa-expected.yaml new file mode 100644 index 000000000..7fd1552f4 --- /dev/null +++ b/integration-tests/goss/rockylinux9/goss-aa-expected.yaml @@ -0,0 +1,17 @@ +package: + httpd: + installed: true + versions: + - 2.4.57-8.el9 +port: + tcp:80: + listening: true + ip: + - 0.0.0.0 +service: + httpd: + enabled: true + running: true +process: + httpd: + running: true diff --git a/integration-tests/goss/rockylinux9/goss-expected-q.yaml b/integration-tests/goss/rockylinux9/goss-expected-q.yaml new file mode 100644 index 000000000..b66ad535a --- /dev/null +++ b/integration-tests/goss/rockylinux9/goss-expected-q.yaml @@ -0,0 +1,127 @@ +file: + /etc/passwd: + exists: true + contents: [] + /tmp/goss/foobar: + exists: false + contents: [] +package: + foobar: + installed: false + httpd: + installed: true + vim-tiny: + installed: false +addr: + tcp://httpbin:22: + reachable: false + timeout: 1000 + tcp://httpbin:80: + reachable: true + timeout: 1000 + udp://8.8.8.8:53: + reachable: true + timeout: 1000 +port: + tcp:80: + listening: true + tcp:9999: + listening: false + tcp6:80: + listening: false +service: + foobar: + enabled: false + running: false + httpd: + enabled: true + running: true +user: + apache: + exists: true + foobar: + exists: false +group: + apache: + exists: true + foobar: + exists: false +command: + echo 'hi': + exit-status: 0 + stdout: "" + stderr: "" + timeout: 10000 + foobar: + exit-status: 127 + stdout: "" + stderr: "" + timeout: 10000 +dns: + CAA:dnstest.io: + resolvable: true + timeout: 1000 + server: 8.8.8.8 + CNAME:c.dnstest.io: + resolvable: true + timeout: 1000 + server: 8.8.8.8 + MX:dnstest.io: + resolvable: true + timeout: 1000 + server: 8.8.8.8 + NS:dnstest.io: + resolvable: true + timeout: 1000 + server: 8.8.8.8 + PTR:54.243.154.1: + resolvable: true + timeout: 1000 + server: 8.8.8.8 + SRV:_https._tcp.dnstest.io: + resolvable: true + timeout: 1000 + server: 8.8.8.8 + TXT:txt._test.dnstest.io: + resolvable: true + timeout: 1000 + server: 8.8.8.8 + ip6.dnstest.io: + resolvable: true + timeout: 1000 + server: 8.8.8.8 + localhost: + resolvable: true + timeout: 1000 +process: + foobar: + running: false + httpd: + running: true +kernel-param: + kernel.ostype: + value: Linux +mount: + /dev: + exists: true + timeout: 1000 +http: + http://google.com: + status: 301 + allow-insecure: false + no-follow-redirects: true + timeout: 5000 + body: [] + https://www.apple.com: + status: 200 + allow-insecure: false + no-follow-redirects: false + timeout: 5000 + body: [] + proxy: http://127.0.0.1:8888 + https://www.google.com: + status: 200 + allow-insecure: false + no-follow-redirects: false + timeout: 5000 + body: [] diff --git a/integration-tests/goss/rockylinux9/goss-expected.yaml b/integration-tests/goss/rockylinux9/goss-expected.yaml new file mode 100644 index 000000000..bbd4249ea --- /dev/null +++ b/integration-tests/goss/rockylinux9/goss-expected.yaml @@ -0,0 +1,177 @@ +file: + /etc/passwd: + exists: true + mode: "0644" + owner: root + group: root + filetype: file + contents: [] + /tmp/goss/foobar: + exists: false + contents: [] +package: + foobar: + installed: false + httpd: + installed: true + versions: + - 2.4.57-8.el9 + vim-tiny: + installed: false +addr: + tcp://httpbin:22: + reachable: false + timeout: 1000 + tcp://httpbin:80: + reachable: true + timeout: 1000 + udp://8.8.8.8:53: + reachable: true + timeout: 1000 +port: + tcp:80: + listening: true + ip: + - 0.0.0.0 + tcp:9999: + listening: false + ip: [] + tcp6:80: + listening: false + ip: [] +service: + foobar: + enabled: false + running: false + httpd: + enabled: true + running: true +user: + apache: + exists: true + uid: 48 + gid: 48 + groups: + - apache + home: /usr/share/httpd + shell: /sbin/nologin + foobar: + exists: false +group: + apache: + exists: true + gid: 48 + foobar: + exists: false +command: + echo 'hi': + exit-status: 0 + stdout: + - hi + stderr: "" + timeout: 10000 + foobar: + exit-status: 127 + stdout: "" + stderr: + - 'sh: line 1: foobar: command not found' + timeout: 10000 +dns: + CAA:dnstest.io: + resolvable: true + addrs: + - 0 issue comodoca.com + - 0 issue letsencrypt.org + - 0 issuewild ; + timeout: 1000 + server: 8.8.8.8 + CNAME:c.dnstest.io: + resolvable: true + addrs: + - a.dnstest.io. + timeout: 1000 + server: 8.8.8.8 + MX:dnstest.io: + resolvable: true + addrs: + - 10 b.dnstest.io. + - 5 a.dnstest.io. + timeout: 1000 + server: 8.8.8.8 + NS:dnstest.io: + resolvable: true + addrs: + - ns1.dnstest.io. + - ns2.dnstest.io. + timeout: 1000 + server: 8.8.8.8 + PTR:54.243.154.1: + resolvable: true + addrs: + - ec2-54-243-154-1.compute-1.amazonaws.com. + timeout: 1000 + server: 8.8.8.8 + SRV:_https._tcp.dnstest.io: + resolvable: true + addrs: + - 0 5 443 a.dnstest.io. + - 10 10 443 b.dnstest.io. + timeout: 1000 + server: 8.8.8.8 + TXT:txt._test.dnstest.io: + resolvable: true + addrs: + - Hello DNS + timeout: 1000 + server: 8.8.8.8 + ip6.dnstest.io: + resolvable: true + addrs: + - 2404:6800:4001:807::200e + timeout: 1000 + server: 8.8.8.8 + localhost: + resolvable: true + addrs: + - 127.0.0.1 + - ::1 + timeout: 1000 +process: + foobar: + running: false + httpd: + running: true +kernel-param: + kernel.ostype: + value: Linux +mount: + /dev: + exists: true + opts: + - rw + - nosuid + vfs-opts: + - rw + source: tmpfs + filesystem: tmpfs + timeout: 1000 +http: + http://google.com: + status: 301 + allow-insecure: false + no-follow-redirects: true + timeout: 5000 + body: [] + https://www.apple.com: + status: 200 + allow-insecure: false + no-follow-redirects: false + timeout: 5000 + body: [] + proxy: http://127.0.0.1:8888 + https://www.google.com: + status: 200 + allow-insecure: false + no-follow-redirects: false + timeout: 5000 + body: [] diff --git a/integration-tests/goss/rockylinux9/goss.yaml b/integration-tests/goss/rockylinux9/goss.yaml new file mode 100644 index 000000000..818b2c34d --- /dev/null +++ b/integration-tests/goss/rockylinux9/goss.yaml @@ -0,0 +1,33 @@ +service: + autofs: + enabled: false + running: false +user: + apache: + exists: true + uid: 48 + gid: 48 + groups: + - apache + home: "/usr/share/httpd" +group: + apache: + exists: true + gid: 48 +process: + httpd: + running: true +port: + tcp:80: + listening: true + ip: + - '0.0.0.0' +addr: + tcp://127.0.0.1:80: + reachable: true + timeout: 500 + local-address: 127.0.0.1 +gossfile: + "../goss-s*.yaml": {} + bypath: + file: "../goss-dummy.yaml" diff --git a/integration-tests/goss/vars.yaml b/integration-tests/goss/vars.yaml index dd505182b..0cc72dbab 100644 --- a/integration-tests/goss/vars.yaml +++ b/integration-tests/goss/vars.yaml @@ -13,6 +13,12 @@ centos7: httpd: "2.4.6-95.el7.centos" services: httpd: [] +rockylinux9: + proxy: http://127.0.0.1:8888 + packages: + httpd: "2.4.57-8.el9" + services: + httpd: [] trusty: proxy: http://127.0.0.1:8888 packages: diff --git a/integration-tests/test.sh b/integration-tests/test.sh index 3225d37bf..2b9936d19 100755 --- a/integration-tests/test.sh +++ b/integration-tests/test.sh @@ -4,7 +4,7 @@ source "$(dirname "${BASH_SOURCE[0]}")/../ci/lib/setup.sh" || exit 67 # preserve current behaviour set -x -os="${1:?"Need OS as 1st arg. e.g. alpine arch centos7 trusty wheezy"}" +os="${1:?"Need OS as 1st arg. e.g. alpine arch centos7 rockylinux9 trusty wheezy"}" arch="${2:?"Need arch as 2nd arg. e.g. amd64 386"}" vars_inline="{inline: bar, overwrite: bar}" @@ -36,7 +36,7 @@ fi network=goss-test docker network create --driver bridge --subnet '172.19.0.0/16' $network docker run -d --name httpbin --network $network kennethreitz/httpbin -opts=(--env OS=$os --cap-add SYS_ADMIN -v "$PWD/goss:/goss" -d --name "$container_name" --security-opt seccomp:unconfined --security-opt label:disable) +opts=(--env OS=$os --cap-add SYS_ADMIN -v "$PWD/goss:/goss" -d --name "$container_name" --security-opt seccomp:unconfined --security-opt label:disable --privileged) id=$(docker run "${opts[@]}" --network $network "aelsabbahy/goss_$os" /sbin/init) ip=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$id") trap "rv=\$?; docker rm -vf $id;docker rm -vf httpbin;docker network rm $network; exit \$rv" INT TERM EXIT