From b7ee8ad39f0e94c2809f13293c3bc0b2356be7c7 Mon Sep 17 00:00:00 2001 From: Jeremy Ho Date: Tue, 4 May 2021 17:12:00 -0700 Subject: [PATCH] Initial commit Signed-off-by: Jeremy Ho --- .editorconfig | 29 +++ .gitattributes | 8 + .github/ISSUE_TEMPLATE/bug_report.md | 46 +++++ .github/ISSUE_TEMPLATE/custom.md | 8 + .github/ISSUE_TEMPLATE/feature_request.md | 24 +++ .github/pull_request_template.md | 29 +++ .github/workflows/docker-image.yaml | 16 ++ .gitignore | 54 +++++ CODE-OF-CONDUCT.md | 46 +++++ COMPLIANCE.yaml | 11 + CONTRIBUTING.md | 9 + LICENSE | 201 ++++++++++++++++++ README.md | 55 +++++ _config.yml | 1 + docker/.dockerignore | 1 + docker/Dockerfile | 17 ++ docker/README.md | 51 +++++ docker/src/Caddyfile | 11 + docker/src/entrypoint.sh | 74 +++++++ openshift/README.md | 161 +++++++++++++++ openshift/app.bc.yaml | 68 +++++++ openshift/app.cronjob.yaml | 151 ++++++++++++++ openshift/app.dc.yaml | 235 ++++++++++++++++++++++ 23 files changed, 1306 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/custom.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/docker-image.yaml create mode 100644 .gitignore create mode 100644 CODE-OF-CONDUCT.md create mode 100644 COMPLIANCE.yaml create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 _config.yml create mode 100644 docker/.dockerignore create mode 100644 docker/Dockerfile create mode 100644 docker/README.md create mode 100644 docker/src/Caddyfile create mode 100644 docker/src/entrypoint.sh create mode 100644 openshift/README.md create mode 100644 openshift/app.bc.yaml create mode 100644 openshift/app.cronjob.yaml create mode 100644 openshift/app.dc.yaml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a3ffe2e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,29 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.html] +indent_style = space +indent_size = 2 + +[*.{css,js,json,jsx,scss,ts,tsx,vue}] +indent_style = space +indent_size = 2 + +[.{babelrc,eslintrc}] +indent_style = space +indent_size = 2 + +[Jenkinsfile*] +indent_style = space +indent_size = 2 + +# ignore patterns +[*.{gif,ico}] +end_of_line = unset +insert_final_newline = unset +trim_trailing_whitespace = unset diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fd57b60 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +# Autodetect text files and forces unix eols, so Windows does not break them +* text=auto eol=lf + +# Force images/fonts to be handled as binaries +*.jpg binary +*.jpeg binary +*.gif binary +*.png binary diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..adc69bc --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,46 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +#### Describe the bug + + + +#### To Reproduce + +Steps to reproduce the behavior: + +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +#### Expected behavior + + + +#### Screenshots + + + +#### Desktop (please complete the following information) + +- OS: [e.g. iOS] +- Browser [e.g. chrome, safari] +- Version [e.g. 22] + +#### Smartphone (please complete the following information) + +- Device: [e.g. iPhone6] +- OS: [e.g. iOS8.1] +- Browser [e.g. stock browser, safari] +- Version [e.g. 22] + +#### Additional context + + diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md new file mode 100644 index 0000000..b894315 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/custom.md @@ -0,0 +1,8 @@ +--- +name: Custom issue template +about: Describe this issue template's purpose here. +title: '' +labels: '' +assignees: '' + +--- diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..2d80c17 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,24 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +#### Is your feature request related to a problem? Please describe + + + +#### Describe the solution you'd like + + + +#### Describe alternatives you've considered + + + +#### Additional context + + diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..e184c36 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,29 @@ + +# Description + + + + + +## Types of changes + + + + + + + + +## Checklist + + + + +- [ ] I have read the [CONTRIBUTING](CONTRIBUTING.md) doc +- [ ] I have checked that unit tests pass locally with my changes +- [ ] I have added tests that prove my fix is effective or that my feature works +- [ ] I have added necessary documentation (if appropriate) + +## Further comments + + diff --git a/.github/workflows/docker-image.yaml b/.github/workflows/docker-image.yaml new file mode 100644 index 0000000..939927e --- /dev/null +++ b/.github/workflows/docker-image.yaml @@ -0,0 +1,16 @@ +--- +name: Docker +on: + - push + - pull_request +jobs: + docker-build: + runs-on: ubuntu-latest + defaults: + run: + working-directory: docker + timeout-minutes: 10 + steps: + - uses: actions/checkout@v2 + - name: Build the Docker image + run: docker build . --file Dockerfile --tag $GITHUB_REPOSITORY:$(date +%s) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5774e45 --- /dev/null +++ b/.gitignore @@ -0,0 +1,54 @@ +# Editor directories and files +.DS_Store +.gradle +.nyc_output +.scannerwork +build +coverage +dist +**/src/formio +**/e2e/videos +node_modules +# Ignore only top-level package-lock.json +/package-lock.json + +# local env files +local.* +local-*.* +.env.local +.env.*.local + +# Log files +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Editor directories and files +.idea +.vscode +*.iml +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? +*.mp4 + +# temp office files +~$* +*.*.bak + +# bddstack files +build +.settings +*.log +.DS_Store +*.ipr +*.iml +*.iws +.env +.idea +.project + +!app/frontend/.env +!local-infrastructure/.env diff --git a/CODE-OF-CONDUCT.md b/CODE-OF-CONDUCT.md new file mode 100644 index 0000000..0c1e1bb --- /dev/null +++ b/CODE-OF-CONDUCT.md @@ -0,0 +1,46 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at matthew.hall@gov.bc.ca. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/COMPLIANCE.yaml b/COMPLIANCE.yaml new file mode 100644 index 0000000..ad14ab2 --- /dev/null +++ b/COMPLIANCE.yaml @@ -0,0 +1,11 @@ +name: compliance +description: | + This document is used to track a projects PIA and STRA + compliance. +spec: + - name: PIA + status: TBD + last-updated: "2021-05-04T00:00:00.000Z" + - name: STRA + status: TBD + last-updated: "2021-05-04T00:00:00.000Z" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..43d4d4a --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,9 @@ +# How to contribute + +Government employees, public and members of the private sector are encouraged to contribute to the repository by **forking and submitting a pull request**. + +(If you are new to GitHub, you might start with a [basic tutorial](https://help.github.com/articles/set-up-git) and check out a more detailed guide to [pull requests](https://help.github.com/articles/using-pull-requests/).) + +Pull requests will be evaluated by the repository guardians on a schedule and if deemed beneficial will be committed to the master. + +All contributors retain the original copyright to their stuff, but by contributing to this project, you grant a world-wide, royalty-free, perpetual, irrevocable, non-exclusive, transferable license to all users **under the terms of the [license](./LICENSE) under which this project is distributed**. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..191f1e0 --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ + +# ClamAV Mirror [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) [![Lifecycle:Maturing](https://img.shields.io/badge/Lifecycle-Maturing-007EC6)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md) + +![Tests](https://github.com/bcgov/common-hosted-form-service/workflows/Docker/badge.svg) + +![Image of ClamAV](https://www.clamav.net/assets/clamav-trademark.png) + +A lightweight containerized ClamAV Mirror using [CVD-Update](https://github.com/Cisco-Talos/cvdupdate) and [Caddy](https://github.com/caddyserver/caddy). + +Run this container to host the ClamAV Database definitions, and leverage a cronjob to periodically update the definitions from upstream. + +## Directory Structure + + .github/ - PR and Issue templates + docker/ - Docker Root + ├── src/ - Docker source files + └── Dockerfile - Main Dockerfile + openshift/ - OpenShift deployment template files + CODE-OF-CONDUCT.md - Code of Conduct + COMPLIANCE.yaml - BCGov PIA/STRA compliance status + CONTRIBUTING.md - Contributing Guidelines + LICENSE - License + +## Documentation + +* [Docker Readme](docker/README.md) +* [Openshift Readme](openshift/README.md) +* [Devops Tools Setup](https://github.com/bcgov/nr-showcase-devops-tools) +* [Product Roadmap](https://github.com/bcgov/common-hosted-form-service/wiki/Product-Roadmap) + +## Getting Help or Reporting an Issue + +To report bugs/issues/features requests, please file an [issue](https://github.com/bcgov/clamav-mirror/issues). + +## How to Contribute + +If you would like to contribute, please see our [contributing](CONTRIBUTING.md) guidelines. + +Please note that this project is released with a [Contributor Code of Conduct](CODE-OF-CONDUCT.md). By participating in this project you agree to abide by its terms. + +## License + + Copyright 2020 Province of British Columbia + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..277f1f2 --- /dev/null +++ b/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-cayman diff --git a/docker/.dockerignore b/docker/.dockerignore new file mode 100644 index 0000000..9414382 --- /dev/null +++ b/docker/.dockerignore @@ -0,0 +1 @@ +Dockerfile diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..f2a33c1 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,17 @@ +FROM docker.io/python:3.9-alpine +ENV PYTHONUNBUFFERED 1 +WORKDIR /opt/app-root/src + +# Install Bash and Caddy +RUN apk add --no-cache bash caddy \ + && rm -rf /var/cache/apk/* + +# Install CVD-Update +RUN pip install --no-cache-dir cvdupdate + +# Copy Scripts +COPY src/ $WORKDIR + +# Start Server +EXPOSE 8080 +CMD [ "./entrypoint.sh", "serve" ] diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..798bca4 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,51 @@ +# ClamAV-Mirror + +This is a Docker Image for a lightweight containerized ClamAV Mirror using [CVD-Update](https://github.com/Cisco-Talos/cvdupdate) and [Caddy](https://github.com/caddyserver/caddy). This image uses Alpine to minimize the image size and unnecessary bloat. + +## Dependencies + +- Docker + +## Quick Start Guide + +Run the following commands to build and run the clamav-mirror Docker image locally. + +### Build + +```sh +docker build . --file Dockerfile --tag clamav-mirror:latest +``` + +### Run (Ephemeral) + +```sh +docker run -it --rm --name clamav-mirror -p 8080:8080 clamav-mirror +``` + +### Run (Persistent) + +```sh +# Create a detached volume +docker volume create cvdupdate + +# Run the mirror with the volume mounted +docker run -it --rm --name clamav-mirror -p 8080:8080 \ + --mount source=cvdupdate,target=/mnt/cvdupdate clamav-mirror + +# Delete the detached volume +docker volume rm cvdupdate +``` + +### Update ClamAV Database definitions + +```sh +docker exec -it clamav-mirror ./entrypoint.sh update +``` + +## ClamAV Configuration + +Once you have the mirror running, you can visit to see what files are hosted by this server. You can then point any of your ClamAV instances to use this mirror instead by changing the following in your `freshclam.conf` file: + +```txt +DatabaseMirror http://localhost:8080 +``` diff --git a/docker/src/Caddyfile b/docker/src/Caddyfile new file mode 100644 index 0000000..5220b3d --- /dev/null +++ b/docker/src/Caddyfile @@ -0,0 +1,11 @@ +{ + admin off + auto_https off + http_port 8080 + https_port 8433 +} + +:8080 { + file_server browse + root * /mnt/cvdupdate/databases +} diff --git a/docker/src/entrypoint.sh b/docker/src/entrypoint.sh new file mode 100644 index 0000000..db55545 --- /dev/null +++ b/docker/src/entrypoint.sh @@ -0,0 +1,74 @@ +#!/bin/bash +set -eo pipefail + +CVD_DIR="${CVD_DIR:=/mnt/cvdupdate}" + +# Configuration Functions +check_config() { + if [ ! -e $CVD_DIR/config.json ]; then + echo "Missing CVD configuration. Creating..." + cvd config set --config $CVD_DIR/config.json --dbdir $CVD_DIR/databases --logdir $CVD_DIR/logs + echo "CVD configuration created..." + fi +} + +show_config() { + echo "CVD-Update configuration..." + cvd config show --config $CVD_DIR/config.json +} + +# CVD Database Functions +check_database() { + if [ ! -e $CVD_DIR/databases ]; then + echo "Missing CVD database directory. Attempting to update..." + check_config + show_config + update_database + fi +} + +serve_database() { + if [ -e $CVD_DIR/databases ]; then + echo "Hosting ClamAV Database..." + if [ -e /mnt/Caddyfile ]; then + echo "Using mounted Caddyfile config..." + exec caddy run --config /mnt/Caddyfile --adapter caddyfile + else + echo "Using default Caddyfile config..." + # exec caddy file-server --listen :8080 --browse --root $CVD_DIR/databases + exec caddy run --config ./Caddyfile --adapter caddyfile + fi + else + echo "CVD database is missing..." + exit 1 + fi +} + +update_database() { + echo "Updating ClamAV Database..." + cvd update --config $CVD_DIR/config.json + echo "ClamAV Database updated..." +} + +# Argument Handler +case "$1" in +status) + check_config + show_config +;; + +serve) + check_database + serve_database +;; + +update) + check_config + show_config + update_database +;; + +*) + echo "Usage: $0 {status|serve|update}" + exit 1 +esac diff --git a/openshift/README.md b/openshift/README.md new file mode 100644 index 0000000..5ace4f1 --- /dev/null +++ b/openshift/README.md @@ -0,0 +1,161 @@ +# Application on Openshift + +This application can be deployed onto Openshift. This readme will outline how to setup and configure an Openshift project to get the application to a deployable state. This document assumes a working knowledge of Kubernetes/Openshift container orchestration concepts (i.e. buildconfigs, deployconfigs, imagestreams, secrets, configmaps, routes, networkpolicies, etc) + +## Table of Contents + +- [Openshift Deployment Prerequisites](#openshift-deployment-prerequisites) +- [Environment Setup - ConfigMaps and Secrets](#environment-setup---configmaps-and-secrets) +- [Build Config & Deployment](#build-config--deployment) +- [Templates](#templates) +- [Pull Request Cleanup](#pull-request-cleanup) + +## Openshift Deployment Prerequisites + +We assume you are logged into OpenShift and are in the repo/openshift local directory. We will run the scripts from there. + +### Add Default Kubernetes Network Policies + +Your namespace should already be a Network Policy named similar to `platform-services-controlled-deny-by-default`. Before deploying, ensure that you have the Network Policy `allow-from-openshift-ingress` by running the following: + +``` sh +export NAMESPACE= + +oc process -n $NAMESPACE -f https://raw.githubusercontent.com/wiki/bcgov/nr-get-token/assets/templates/default.np.yaml | oc apply -n $NAMESPACE -f - +``` + +## Environment Setup - ConfigMaps and Secrets + +This application requires a Config Map to define the Caddyfile configuration. However, this is embedded as a part of the deployment template, so no manual steps are required to have it be deployed. This application does not need to manage secrets. + +## Build Config & Deployment + +This application is currently designed as a single application pod deployment. It will host a Caddy static frontend which will host all of the ClamAV Database definitions. We are currently leveraging Openshift Routes to forward incoming traffic to the right deployment service. The application can also update the database definitions at any time via a different entrypoint command. + +## Templates + +The Jenkins pipeline heavily leverages Openshift Templates in order to ensure that all of the environment variables, settings, and contexts are pushed to Openshift correctly. Files ending with `.bc.yaml` specify the build configurations, while files ending with `.dc.yaml` specify the components required for deployment. + +### Build Configurations + +Build configurations will emit and handle the chained builds or standard builds as necessary. They take in the following parameters: + +| Name | Required | Description | +| --- | --- | --- | +| BASE_IMAGE | yes | Base Image to build from | +| REPO_NAME | yes | Application repository name | +| SOURCE_REPO_REF | yes | Git Pull Request Reference (i.e. 'pull/CHANGE_ID/head') | +| SOURCE_REPO_URL | yes | Git Repository URL | + +The template can be manually invoked and deployed via Openshift CLI. For example: + +```sh +export NAMESPACE= + +oc process -n $NAMESPACE -f openshift/app.bc.yaml -p REPO_NAME=clamav-mirror -p SOURCE_REPO_URL=https://github.com/bcgov/clamav-mirror.git -p SOURCE_REPO_REF=master -o yaml | oc apply -n $NAMESPACE -f - +``` + +Note that these build configurations do not have any triggers defined. They need to be started manually in the console, or by an equivalent oc command for example: + +```sh +oc start-build -n $NAMESPACE --follow +``` + +While this deployment does not use explicitly managed tags (sticks with the latest build tag instead), we generally tag the resultant image so that the deployment config will know which exact image to use. The equivalent oc command for example is: + +```sh +oc tag -n $NAMESPACE :latest :master +``` + +*Note: Remember to swap out the bracketed values with the appropriate values!* + +### Deployment Configurations + +Deployment configurations will emit and handle the deployment lifecycles of running containers based off of the previously built images. They generally contain a deploymentconfig, a service, and a route. + +Our application template take in mainly the following parameters: + +| Name | Required | Description | +| --- | --- | --- | +| APP_NAME | yes | short name for the application | +| INSTANCE | yes | The name of this instance of the application | +| NAMESPACE | yes | which namespace/"environment" are we deploying to? dev, test, prod? | +| REPO_NAME | yes | Application repository name | +| ROUTE_HOST | yes | The host the route will use to expose service outside cluster | + +Deployment invocation can be done manually with the following for example: + +```sh +export NAMESPACE= +export APP_NAME= + +oc process -n $NAMESPACE -f openshift/app.dc.yaml -p APP_NAME=$APP_NAME -p INSTANCE=master -p NAMESPACE=$NAMESPACE -p REPO_NAME=clamav-mirror -p ROUTE_HOST=clamav-mirror.apps.silver.devops.gov.bc.ca -o yaml | oc apply -n $NAMESPACE -f - +``` + +Due to the triggers that are set in the deploymentconfig, the deployment will begin automatically. However, you can deploy manually by use the following command for example: + +```sh +oc rollout -n $NAMESPACE latest dc/ +``` + +*Note: Remember to swap out the bracketed values with the appropriate values!* + +### Cronjob Configurations + +This application also supports a periodic update via a CronJob based off of the previously built images. They are generally time-restricted tasks. + +Our application template take in mainly the following parameters: + +| Name | Required | Description | +| --- | --- | --- | +| APP_NAME | yes | short name for the application | +| INSTANCE | yes | The name of this instance of the application | +| NAMESPACE | yes | which namespace/"environment" are we deploying to? dev, test, prod? | +| REPO_NAME | yes | Application repository name | +| CRON_SCHEDULE | no | CronJob crontab schedule | + +Cronjob invocation can be done manually with the following for example: + +```sh +export NAMESPACE= +export APP_NAME= + +oc process -n $NAMESPACE -f openshift/app.cronjob.yaml -p APP_NAME=$APP_NAME -p INSTANCE=master -p NAMESPACE=$NAMESPACE -p REPO_NAME=clamav-mirror -o yaml | oc apply -n $NAMESPACE -f - +``` + +#### Manual Run + +This CronJob will run based off of the specified `CRON_SCHEDULE`, which defaults to `0 */8 * * *` or running once every 8 hours. However, you can run the job manually by use the following command for example: + +```sh +export NAMESPACE= +export APP_NAME= + +oc create -n $NAMESPACE job --from=cronjob/$APP_NAME-updater "$APP_NAME-updater-manual-$(date +%s)" +``` + +If the update runs successfully, it will show as 'Completed', and you can inspect the logs. + +Make sure to clean up your temporary pod when you are done with the following: + +```sh +export NAMESPACE= + +# Note: When there are no jobs to delete, you will get an error for oc delete. +oc get job -n $NAMESPACE -o name | grep -F -e '-manual-' | xargs oc delete -n $NAMESPACE +``` + +*Note: Remember to swap out the bracketed values with the appropriate values!* + +## Pull Request Cleanup + +As of this time, we do not automatically clean up resources generated by a Pull Request once it has been accepted and merged in. This is still a manual process. Our PR deployments are all named in the format "pr-###", where the ### is the number of the specific PR. In order to clear all resources for a specific PR, run the following two commands to delete all relevant resources from the Openshift project (replacing `PRNUMBER` with the appropriate number): + +```sh +export NAMESPACE= +export APP_NAME= + +oc delete all,secret,pvc,networkpolicy -n $NAMESPACE -l app=$APP_NAME-app +``` + +The command will clear out all related executable resources for the application associated with that PR. diff --git a/openshift/app.bc.yaml b/openshift/app.bc.yaml new file mode 100644 index 0000000..bf0fd1b --- /dev/null +++ b/openshift/app.bc.yaml @@ -0,0 +1,68 @@ +--- +apiVersion: v1 +kind: Template +labels: + build: "${REPO_NAME}-app" + template: "${REPO_NAME}-app-bc-template" +metadata: + name: "${REPO_NAME}-app-bc" +objects: + - apiVersion: v1 + kind: ImageStream + metadata: + name: "${REPO_NAME}-app" + spec: + lookupPolicy: + local: false + - apiVersion: v1 + kind: BuildConfig + metadata: + name: "${REPO_NAME}-app" + spec: + completionDeadlineSeconds: 600 + failedBuildsHistoryLimit: 3 + nodeSelector: + output: + to: + kind: ImageStreamTag + name: "${REPO_NAME}-app:latest" + postCommit: {} + resources: + requests: + cpu: 2000m + memory: 1Gi + limits: + cpu: 4000m + memory: 2Gi + runPolicy: SerialLatestOnly + source: + contextDir: docker + git: + ref: "${SOURCE_REPO_REF}" + uri: "${SOURCE_REPO_URL}" + type: Git + strategy: + dockerStrategy: + from: + kind: DockerImage + name: "${BASE_IMAGE}" + type: Docker + successfulBuildsHistoryLimit: 3 +parameters: + - name: BASE_IMAGE + description: Base Image to build from + displayName: Base Image + required: true + value: docker.io/python:3.9-alpine + - name: REPO_NAME + description: Application repository name + displayName: Repository Name + required: true + - name: SOURCE_REPO_REF + description: Git Pull Request Reference (i.e. 'pull/CHANGE_ID/head') + displayName: Source Repository Reference + required: true + - name: SOURCE_REPO_URL + description: Git Repository URL + displayName: Source Repository URL + required: true diff --git a/openshift/app.cronjob.yaml b/openshift/app.cronjob.yaml new file mode 100644 index 0000000..82109a0 --- /dev/null +++ b/openshift/app.cronjob.yaml @@ -0,0 +1,151 @@ +--- +apiVersion: v1 +kind: Template +labels: + app: "${APP_NAME}-updater" + app.kubernetes.io/component: updater + app.kubernetes.io/instance: ${INSTANCE} + app.kubernetes.io/name: python + app.kubernetes.io/managed-by: template + app.kubernetes.io/part-of: ${APP_NAME}-${INSTANCE} + app.kubernetes.io/version: "3.9" + app.openshift.io/runtime: python + template: "${REPO_NAME}-updater-template" +metadata: + name: "${REPO_NAME}-updater-dc" +objects: + - apiVersion: batch/v1beta1 + kind: CronJob + metadata: + name: "${APP_NAME}-updater" + spec: + concurrencyPolicy: Replace + failedJobsHistoryLimit: 3 + successfulJobsHistoryLimit: 5 + startingDeadlineSeconds: 60 + jobTemplate: + metadata: + labels: + app: "${APP_NAME}-updater" + app.kubernetes.io/component: updater + app.kubernetes.io/instance: ${INSTANCE} + app.kubernetes.io/name: python + app.kubernetes.io/managed-by: template + app.kubernetes.io/part-of: ${APP_NAME}-${INSTANCE} + app.kubernetes.io/version: "3.9" + app.openshift.io/runtime: python + template: "${REPO_NAME}-updater-template" + spec: + activeDeadlineSeconds: 600 + backoffLimit: 1 + completions: 1 + parallelism: 1 + template: + metadata: + labels: + app: "${APP_NAME}-updater" + app.kubernetes.io/component: updater + app.kubernetes.io/instance: ${INSTANCE} + app.kubernetes.io/name: python + app.kubernetes.io/managed-by: template + app.kubernetes.io/part-of: ${APP_NAME}-${INSTANCE} + app.kubernetes.io/version: "3.9" + app.openshift.io/runtime: python + template: "${REPO_NAME}-updater-template" + spec: + containers: + - name: updater + image: "${IMAGE_REGISTRY}/${NAMESPACE}/${REPO_NAME}-app:latest" + imagePullPolicy: IfNotPresent + command: + - "./entrypoint.sh" + - "update" + resources: + requests: + cpu: ${CPU_REQUEST} + memory: ${MEMORY_REQUEST} + limits: + cpu: ${CPU_LIMIT} + memory: ${MEMORY_LIMIT} + env: + - name: CVD_DIR + value: "${DATA_DIR}" + volumeMounts: + - mountPath: "${DATA_DIR}" + name: data + restartPolicy: Never + terminationGracePeriodSeconds: 30 + volumes: + - name: data + persistentVolumeClaim: + claimName: "${APP_NAME}-data" + schedule: "${CRON_SCHEDULE}" + suspend: "${{SUSPEND_CRON}}" +parameters: + - name: APP_NAME + description: Application name + displayName: Application name + required: true + - name: INSTANCE + description: The name of this instance of the application + displayName: Application Instance Name + required: true + value: master + - name: IMAGE_REGISTRY + description: The base docker registry + displayName: Docker Image Registry + required: true + value: docker.io + - name: NAMESPACE + description: Target namespace reference (i.e. 'wfezkf-dev') + displayName: Target Namespace + required: true + - name: REPO_NAME + description: Application repository name + displayName: Repository Name + required: true + # https://crontab.guru/every-8-hours + - name: CRON_SCHEDULE + description: CronJob crontab schedule + displayName: Crontab schedule + required: false + value: "0 */8 * * *" + - name: SUSPEND_CRON + description: Suspend this CronJob + displayName: Suspend CronJob + required: false + value: false + - name: CPU_REQUEST + description: Starting amount of CPU the container can use. + displayName: CPU Request + required: true + value: 50m + - name: CPU_LIMIT + description: Maximum amount of CPU the container can use. + displayName: CPU Limit + required: true + value: 250m + - name: MEMORY_REQUEST + description: Starting amount of memory the container can use. + displayName: Memory Request + required: true + value: 64Mi + - name: MEMORY_LIMIT + description: Maximum amount of memory the container can use. + displayName: Memory Limit + required: true + value: 256Mi + - name: DATA_DIR + description: Path to data directory + displayName: Directory to mount for data files + required: true + value: "/mnt/cvdupdate" + - name: DATA_VOLUME_CAPACITY + description: Volume space available for Data + displayName: Data Volume Capacity (use M or G, not Mi or Gi) + required: true + value: 1G + - name: DATA_PERSISTENT_VOLUME_CLASS + description: The storage class of the volume + displayName: Persistent Volume Class name + value: netapp-file-standard diff --git a/openshift/app.dc.yaml b/openshift/app.dc.yaml new file mode 100644 index 0000000..171c77f --- /dev/null +++ b/openshift/app.dc.yaml @@ -0,0 +1,235 @@ +--- +apiVersion: v1 +kind: Template +metadata: + annotations: + description: Caddy Server + iconClass: icon-caddy + openshift.io/display-name: Caddy Server + openshift.io/long-description: | + Caddy 2 is a powerful, enterprise-ready, open source web server with automatic HTTPS written in Go. + tags: caddy + name: "${REPO_NAME}-app-dc" +labels: + app: "${APP_NAME}-app" + app.kubernetes.io/component: app + app.kubernetes.io/instance: ${INSTANCE} + app.kubernetes.io/name: caddy + app.kubernetes.io/managed-by: template + app.kubernetes.io/part-of: ${APP_NAME}-${INSTANCE} + app.kubernetes.io/version: "2" + app.openshift.io/runtime: golang + template: "${REPO_NAME}-app-template" +objects: + - apiVersion: v1 + kind: ConfigMap + metadata: + name: "${APP_NAME}-caddyfile" + data: + Caddyfile: | + { + admin off + auto_https off + http_port 8080 + https_port 8433 + } + + :8080 { + file_server browse + root * ${DATA_DIR}/databases + } + - apiVersion: v1 + kind: DeploymentConfig + metadata: + name: "${APP_NAME}-app" + spec: + replicas: ${{REPLICAS}} + selector: + app: "${APP_NAME}-app" + deploymentconfig: "${APP_NAME}-app" + role: app + strategy: + resources: {} + type: Rolling + template: + metadata: + labels: + app: "${APP_NAME}-app" + app.kubernetes.io/component: app + app.kubernetes.io/instance: ${INSTANCE} + app.kubernetes.io/name: caddy + app.kubernetes.io/managed-by: template + app.kubernetes.io/part-of: ${APP_NAME}-${INSTANCE} + app.kubernetes.io/version: "2" + app.openshift.io/runtime: golang + deploymentconfig: "${APP_NAME}-app" + role: app + template: "${REPO_NAME}-app-template" + spec: + containers: + - name: app + image: "${IMAGE_REGISTRY}/${NAMESPACE}/${REPO_NAME}-app:latest" + imagePullPolicy: IfNotPresent + livenessProbe: + tcpSocket: + port: 8080 + periodSeconds: 10 + timeoutSeconds: 1 + failureThreshold: 3 + ports: + - containerPort: 8080 + name: http + - containerPort: 8433 + name: https + readinessProbe: + tcpSocket: + port: 8080 + periodSeconds: 10 + timeoutSeconds: 1 + failureThreshold: 1 + resources: + requests: + cpu: ${CPU_REQUEST} + memory: ${MEMORY_REQUEST} + limits: + cpu: ${CPU_LIMIT} + memory: ${MEMORY_LIMIT} + env: + - name: CVD_DIR + value: "${DATA_DIR}" + volumeMounts: + - mountPath: /mnt + name: caddyfile + readOnly: true + - mountPath: "${DATA_DIR}" + name: data + restartPolicy: Always + terminationGracePeriodSeconds: 30 + volumes: + - name: caddyfile + configMap: + defaultMode: 420 + name: "${APP_NAME}-caddyfile" + - name: data + persistentVolumeClaim: + claimName: "${APP_NAME}-data" + test: false + triggers: + - type: ConfigChange + - imageChangeParams: + automatic: true + containerNames: + - app + from: + kind: ImageStreamTag + name: "${REPO_NAME}-app:latest" + namespace: "${NAMESPACE}" + type: ImageChange + - apiVersion: v1 + kind: PersistentVolumeClaim + metadata: + name: "${APP_NAME}-data" + spec: + accessModes: + - ReadWriteMany + storageClassName: "${DATA_PERSISTENT_VOLUME_CLASS}" + resources: + requests: + storage: "${DATA_VOLUME_CAPACITY}" + - apiVersion: v1 + kind: Route + metadata: + name: "${APP_NAME}-app" + spec: + host: "${ROUTE_HOST}" + path: / + port: + targetPort: http + tls: + insecureEdgeTerminationPolicy: Redirect + termination: edge + to: + kind: Service + name: "${APP_NAME}-app" + weight: 100 + wildcardPolicy: None + - apiVersion: v1 + kind: Service + metadata: + name: "${APP_NAME}-app" + spec: + ports: + - name: http + port: 8080 + - name: https + port: 8433 + selector: + app: "${APP_NAME}-app" + deploymentconfig: "${APP_NAME}-app" + role: app +parameters: + - name: APP_NAME + description: Application name + displayName: Application name + required: true + - name: INSTANCE + description: The name of this instance of the application + displayName: Application Instance Name + required: true + value: master + - name: REPLICAS + description: The number of replicas to use. + displayName: Replicas + required: true + value: "2" + - name: IMAGE_REGISTRY + description: The base docker registry + displayName: Docker Image Registry + required: true + value: docker.io + - name: NAMESPACE + description: Target namespace reference (i.e. 'wfezkf-dev') + displayName: Target Namespace + required: true + - name: REPO_NAME + description: Application repository name + displayName: Repository Name + required: true + - name: ROUTE_HOST + description: The host the route will use to expose service outside cluster + displayName: Route host + required: true + - name: CPU_REQUEST + description: Starting amount of CPU the container can use. + displayName: CPU Request + required: true + value: 50m + - name: CPU_LIMIT + description: Maximum amount of CPU the container can use. + displayName: CPU Limit + required: true + value: 250m + - name: MEMORY_REQUEST + description: Starting amount of memory the container can use. + displayName: Memory Request + required: true + value: 64Mi + - name: MEMORY_LIMIT + description: Maximum amount of memory the container can use. + displayName: Memory Limit + required: true + value: 256Mi + - name: DATA_DIR + description: Path to data directory + displayName: Directory to mount for data files + required: true + value: "/mnt/cvdupdate" + - name: DATA_VOLUME_CAPACITY + description: Volume space available for Data + displayName: Data Volume Capacity (use M or G, not Mi or Gi) + required: true + value: 1G + - name: DATA_PERSISTENT_VOLUME_CLASS + description: The storage class of the volume + displayName: Persistent Volume Class name + value: netapp-file-standard