Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Add the docker portions of pca-report-library #10

Open
wants to merge 79 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
89145e2
Add users to CODEOWNERS file
ameliav Oct 21, 2021
8bddd3b
Remove unneeded ports from docker-compose.yml
ameliav Oct 21, 2021
c0c141d
Merge pca-report-library Dockerfile with this one
ameliav Oct 22, 2021
e52afdb
Update image name in build.yml
ameliav Oct 22, 2021
5146fa9
Update Dockerfile to working state
ameliav Oct 22, 2021
f496a40
Remove platforms from build.yml
ameliav Oct 22, 2021
fc68801
Add docker commands to README.md
ameliav Oct 22, 2021
49c27b1
Remove ports section from README.md
ameliav Oct 25, 2021
8cc7e86
Update Environment variables section in README.md
ameliav Oct 25, 2021
2f60a6e
Add volume path to Dockerfile
ameliav Oct 25, 2021
7eb548c
Remove unneeded sections from README.md
ameliav Oct 25, 2021
35aade2
Update container name in docker-compose.yml
ameliav Oct 27, 2021
0ce564c
Update wait_for_ready and output tests
ameliav Oct 27, 2021
1527721
Fix back container error code in container_test.py
ameliav Oct 29, 2021
8eb36c5
Update version label key in container_test.py
ameliav Oct 29, 2021
f6a68ff
Update MAIN_SERVICE_NAME in conftest.py
ameliav Oct 29, 2021
c62293b
Add copying over version.txt in Dockerfile
ameliav Oct 29, 2021
825d6e1
Update service command in docker-compose.yml
ameliav Oct 29, 2021
d723194
Update the docker compose section of README.md
ameliav Oct 29, 2021
b650f78
Re-add platforms to build.yml
ameliav Nov 5, 2021
d45b1c1
Add braces to PCA_REPORT_TOOLS_SRC in Dockerfile
ameliav Nov 5, 2021
2030740
Add braces to CISA_HOME in Dockerfile
ameliav Nov 5, 2021
b2ce069
Capitalize the word Docker in README
ameliav Nov 5, 2021
c8f5a55
Simplify pca-report-generator summary in README
ameliav Nov 5, 2021
4764d7d
Update pca-report-generator-bash summary in README
ameliav Nov 5, 2021
0df5d73
Merge branch 'PCADEV-197-customize' of github.com:cisagov/pca-report-…
ameliav Nov 5, 2021
f85cb89
Add version tag to image in docker-compose
ameliav Nov 5, 2021
b6631f2
Merge branch 'PCADEV-197-customize' of github.com:cisagov/pca-report-…
ameliav Nov 5, 2021
fc03e8e
Add version tag to image in docker-compose
ameliav Nov 5, 2021
1275338
Merge branch 'PCADEV-197-customize' of github.com:cisagov/pca-report-…
ameliav Nov 5, 2021
dad82c5
Uncomment buildx statement in README
ameliav Nov 5, 2021
307f24c
Update numbering item in README
ameliav Nov 5, 2021
8b4a5ab
Add image version tag to README
ameliav Nov 5, 2021
8d9ac4a
Merge branch 'PCADEV-197-customize' of github.com:cisagov/pca-report-…
ameliav Nov 5, 2021
598acee
Re-add and update sections into the README
ameliav Nov 5, 2021
af48f3c
Uncomment optional environment variable in README
ameliav Nov 5, 2021
ea18e21
Update docker environment variables in README
ameliav Nov 5, 2021
a8f6a04
Re-add ports section in README
ameliav Nov 5, 2021
933aa56
Add image version tag to README
ameliav Nov 5, 2021
f9ed352
Uncomment end of image tags section in README
ameliav Nov 5, 2021
079d2e9
Uncomment top of image tags section in README
ameliav Nov 5, 2021
7cbc7c7
Update image tag release numbers in README
ameliav Nov 5, 2021
91c7b63
Remove docker debug command in README
ameliav Nov 5, 2021
74e995f
Update intro docker project summary in README
ameliav Nov 5, 2021
2b0eba1
Remove secrets from docker-compose
ameliav Nov 8, 2021
4ef3793
Comment out secrets section in README
ameliav Nov 8, 2021
a9238ed
Merge branch 'PCADEV-197-customize' of github.com:cisagov/pca-report-…
ameliav Nov 8, 2021
3095f9c
Remove unneeded volume creation in Dockerfile
ameliav Nov 8, 2021
f8c135f
Comment out volumes section in README
ameliav Nov 8, 2021
c15795b
Remove using secrets with your container in README
ameliav Nov 8, 2021
1be4e84
Comment out secrets section in README
ameliav Nov 8, 2021
9d72a51
Remove unused secrets quote from container_test.py
ameliav Nov 8, 2021
cf1db91
Remove git_commit labels from Dockerfile
ameliav Nov 8, 2021
b7a940d
Remove version label in Dockerfile
ameliav Nov 8, 2021
2f9cd7a
Remove GIT ARGs from Dockerfile
ameliav Nov 8, 2021
c718294
Update version key in container_test.py
ameliav Nov 9, 2021
7286a3c
Remove GIT ARGS from Dockerfile
ameliav Nov 10, 2021
4d038c2
Alphabetize env variables in README
ameliav Nov 10, 2021
cfb0e95
Update version to unspecified in Dockerfile
ameliav Nov 10, 2021
642ef11
Remove versions on the images in docker-compose
ameliav Nov 10, 2021
b4f38da
Remove all instances of ECHO_MESSAGE env variable
ameliav Nov 12, 2021
c56cbe2
Remove unused variables from container_test.py
ameliav Nov 15, 2021
ebc3182
Consolidate and update RUN commands in Dockerfile
ameliav Nov 15, 2021
a9e9a3e
Update var to PCA_REPORT_LIBRARY_SRC in Dockerfile
ameliav Nov 15, 2021
eb3bd0c
Add TODO about updating to Alpine in Dockerfile
ameliav Nov 15, 2021
02a0524
Update TODO with python:3.9.6 image in Dockerfile
ameliav Nov 16, 2021
64810e1
Update TODO wording in Dockerfile
ameliav Nov 16, 2021
19beb67
Add entrypoint pca-report-generator to Dockerfile
ameliav Nov 16, 2021
120e86b
Update version command in docker-compose
ameliav Nov 16, 2021
c494107
Merge branch 'PCADEV-197-customize' of github.com:cisagov/pca-report-…
ameliav Nov 16, 2021
2408f6a
Update docker commands per entrypoint in README
ameliav Nov 16, 2021
2cd9701
Add TODO about updating entrypoint in Dockerfile
ameliav Nov 18, 2021
eed0469
Imrpove explanatory text in the README
ameliav Nov 18, 2021
081047b
Improve and correct docker run examples in README
ameliav Nov 18, 2021
4be5029
Improve pca-report-compiler summary text in README
ameliav Nov 18, 2021
2f7a076
Update docker run example in README
ameliav Nov 18, 2021
8d3e8fb
Update command to start up bash shell in README
ameliav Nov 18, 2021
4df844d
Correct repo name in README
ameliav Nov 18, 2021
a9c92b2
Correct repo name in clone command in README
ameliav Nov 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# These owners will be the default owners for everything in the
# repo. Unless a later match takes precedence, these owners will be
# requested for review when someone opens a pull request.
* @dav3r @felddy @jsf9k @mcdonnnj
* @ameliav @BenBreaksThings @dav3r @felddy @JCantu248 @jsf9k @king-alexander @mcdonnnj @nickviola

# These folks own any files in the .github directory at the root of
# the repository and any of its subdirectories.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ on:
env:
BUILDX_CACHE_DIR: ~/.cache/buildx
CURL_CACHE_DIR: ~/.cache/curl
IMAGE_NAME: cisagov/example
IMAGE_NAME: cisagov/pca-report-library
PIP_CACHE_DIR: ~/.cache/pip
PLATFORMS: "linux/amd64,linux/arm/v6,linux/arm/v7,\
linux/arm64,linux/ppc64le,linux/s390x"
Expand Down
34 changes: 20 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ARG VERSION=unspecified

FROM python:3.9.6-alpine
# TODO: Switch base Docker image from python:3.9.6 to a current
# alpine image (e.g. python:3.10.0-alpine)
# Issue: https://github.com/cisagov/pca-report-generator-docker/issues/11
FROM python:3.9.6
dav3r marked this conversation as resolved.
Show resolved Hide resolved

ARG VERSION

Expand All @@ -12,27 +14,31 @@ LABEL org.opencontainers.image.vendor="Cybersecurity and Infrastructure Security

ARG CISA_UID=421
ENV CISA_HOME="/home/cisa"
ENV PCA_REPORT_LIBRARY_SRC="/usr/src/pca-report-tools"
ENV ECHO_MESSAGE="Hello World from Dockerfile"
dav3r marked this conversation as resolved.
Show resolved Hide resolved

RUN addgroup --system --gid ${CISA_UID} cisa \
&& adduser --system --uid ${CISA_UID} --ingroup cisa cisa

RUN apk --update --no-cache add \
ca-certificates \
openssl \
py-pip
RUN apt-get update && \
apt-get install --no-install-recommends -y texlive texlive-bibtex-extra texlive-xetex wget

WORKDIR ${CISA_HOME}
COPY src/version.txt /src

WORKDIR ${PCA_REPORT_LIBRARY_SRC}

RUN wget -O sourcecode.tgz https://github.com/cisagov/skeleton-python-library/archive/v${VERSION}.tar.gz && \
RUN wget -O sourcecode.tgz https://github.com/cisagov/pca-report-library/archive/v${VERSION}.tar.gz && \
tar xzf sourcecode.tgz --strip-components=1 && \
pip install --requirement requirements.txt && \
dav3r marked this conversation as resolved.
Show resolved Hide resolved
ln -snf /run/secrets/quote.txt src/example/data/secret.txt && \
cp -r src/pca_report_library/assets/fonts /usr/share/fonts/truetype/ncats && \
fc-cache -fsv && \
chmod +x ${PCA_REPORT_LIBRARY_SRC}/var/getenv && \
ln -snf ${PCA_REPORT_LIBRARY_SRC}/var/getenv /usr/local/bin && \
rm sourcecode.tgz

USER cisa

EXPOSE 8080/TCP
VOLUME ["/var/log"]
ENTRYPOINT ["example"]
dav3r marked this conversation as resolved.
Show resolved Hide resolved
CMD ["--log-level", "DEBUG"]
WORKDIR ${CISA_HOME}
# TODO: Create a shell script to improve the Docker entrypoint
# Issue: https://github.com/cisagov/pca-report-generator-docker/issues/12
ENTRYPOINT ["pca-report-generator"]
CMD ["--help"]
158 changes: 67 additions & 91 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pca-report-generator-docker 💀🐳 #
# pca-report-generator-docker #
Copy link
Member

@dav3r dav3r Nov 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the recent items that I noted have made me realize that this repo should really be called pca-report-library-docker, since it containerizes pca-report-library. Let's take care of that name change (and the related changes to the README) as the final step after all of the other conversations in this PR have been resolved.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dav3r okay- please let me know when and how to take care of this or if you will

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dav3r when you are back from vacation, please let me know if everything else has been resolved and then how to take care of the repo name change, thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do @ameliav - I am going try to get back to you on this tomorrow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repo name change is pretty simple- I'm thinking we should change the repo name as soon as this PR is merged. I can take care of the renaming. In the meantime, you should update the README and change anything that says pca-report-generator-docker to pca-report-library-docker.

In addition to that, you still have to get the failing tests to pass. Let me know if you need any help there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dav3r thanks for getting back. I've been assigned to another task so this has been put on hold for me. Will comment again when I'm able to work on this again.


[![GitHub Build Status](https://github.com/cisagov/pca-report-generator-docker/workflows/build/badge.svg)](https://github.com/cisagov/pca-report-generator-docker/actions/workflows/build.yml)
[![CodeQL](https://github.com/cisagov/pca-report-generator-docker/workflows/CodeQL/badge.svg)](https://github.com/cisagov/pca-report-generator-docker/actions/workflows/codeql-analysis.yml)
Expand All @@ -10,21 +10,49 @@
[![Docker Image Size (latest by date)](https://img.shields.io/docker/image-size/cisagov/example)](https://hub.docker.com/r/cisagov/example)
[![Platforms](https://img.shields.io/badge/platforms-amd64%20%7C%20arm%2Fv6%20%7C%20arm%2Fv7%20%7C%20arm64%20%7C%20ppc64le%20%7C%20s390x-blue)](https://hub.docker.com/r/cisagov/pca-report-generator-docker/tags)

This is a Docker skeleton project that can be used to quickly get a
new [cisagov](https://github.com/cisagov) GitHub Docker project
started. This skeleton project contains [licensing
information](LICENSE), as well as [pre-commit hooks](https://pre-commit.com)
and [GitHub Actions](https://github.com/features/actions) configurations
appropriate for Docker containers and the major languages that we use.
This is a Docker project that containerizes the [pca-report-library](https://github.com/cisagov/pca-report-library)
package, which can be used to generate Phishing Campaign Assessment (PCA) reports.

## Running ##

### Running with Docker ###
The following Docker commands are available.

To run the `cisagov/example` image via Docker:
Use `--entrypoint` to select which command within `pca-report-library` to
execute:

- `pca-report-generator` (this is the default entrypoint)
- `pca-report-templates`
- `pca-report-compiler`

If no additional parameters are supplied, help text will be output.
See below for examples:

`pca-report-generator` - Create a PCA report as a PDF:

```console
docker run cisagov/example:0.0.1
docker run --volume $(pwd):/home/cisa cisagov/pca-report-library:0.0.1 MY_ASSESSMENT_ID
```

`pca-report-templates` - Export the PCA manual data file template or Mustache
template:

```console
docker run --volume $(pwd):/home/cisa --entrypoint pca-report-templates cisagov/pca-report-library:0.0.1 --manualData

docker run --volume $(pwd):/home/cisa --entrypoint pca-report-templates cisagov/pca-report-library:0.0.1 --LaTeX
```

`pca-report-compiler` - Compile a PCA LaTeX report file (still in
development):

```console
docker run --volume $(pwd):/home/cisa --entrypoint pca-report-templates cisagov/pca-report-library:0.0.1 MY_REPORT.tex
```

Start up a `bash` shell in a `pca-report-library` container:

```console
docker run -v $(pwd):/home/cisa --entrypoint /bin/bash --interactive --tty cisagov/pca-report-library:0.0.1
```

### Running with Docker Compose ###
Expand All @@ -36,18 +64,12 @@ docker run cisagov/example:0.0.1
version: "3.7"

services:
example:
image: cisagov/example:0.0.1
pca-report-library:
image: cisagov/pca-report-library:0.0.1
volumes:
- type: bind
source: <your_log_dir>
target: /var/log
environment:
- ECHO_MESSAGE="Hello from docker-compose"
ports:
- target: 8080
published: 8080
protocol: tcp
target: /home/cisa
```

1. Start the container and detach:
Expand All @@ -56,48 +78,6 @@ docker run cisagov/example:0.0.1
docker-compose up --detach
```

## Using secrets with your container ##

This container also supports passing sensitive values via [Docker
secrets](https://docs.docker.com/engine/swarm/secrets/). Passing sensitive
values like your credentials can be more secure using secrets than using
environment variables. See the
[secrets](#secrets) section below for a table of all supported secret files.

1. To use secrets, create a `quote.txt` file containing the values you want set:

```text
Better lock it in your pocket.
```

1. Then add the secret to your `docker-compose.yml` file:

```yaml
---
version: "3.7"

secrets:
quote_txt:
file: quote.txt

services:
example:
image: cisagov/example:0.0.1
volumes:
- type: bind
source: <your_log_dir>
target: /var/log
environment:
- ECHO_MESSAGE="Hello from docker-compose"
ports:
- target: 8080
published: 8080
protocol: tcp
secrets:
- source: quote_txt
target: quote.txt
```

## Updating your container ##

### Docker Compose ###
Expand Down Expand Up @@ -125,7 +105,7 @@ environment variables. See the
1. Pull the new image:

```console
docker pull cisagov/example:0.0.1
docker pull cisagov/pca-report-library:0.0.1
```

1. Recreate and run the container by following the [previous instructions](#running-with-docker).
Expand All @@ -139,24 +119,28 @@ containerize. It is recommended that most users use a version tag (e.g.

| Image:tag | Description |
|-----------|-------------|
|`cisagov/example:1.2.3`| An exact release version. |
|`cisagov/example:1.2`| The most recent release matching the major and minor version numbers. |
|`cisagov/example:1`| The most recent release matching the major version number. |
|`cisagov/example:edge` | The most recent image built from a merge into the `develop` branch of this repository. |
|`cisagov/example:nightly` | A nightly build of the `develop` branch of this repository. |
|`cisagov/example:latest`| The most recent release image pushed to a container registry. Pulling an image using the `:latest` tag [should be avoided.](https://vsupalov.com/docker-latest-tag/) |
|`cisagov/pca-report-library:0.0.1`| An exact release version. |
|`cisagov/pca-report-library:0.0`| The most recent release matching the major and minor version numbers. |
|`cisagov/pca-report-library:0`| The most recent release matching the major version number. |
|`cisagov/pca-report-library:edge` | The most recent image built from a merge into the `develop` branch of this repository. |
|`cisagov/pca-report-library:nightly` | A nightly build of the `develop` branch of this repository. |
|`cisagov/pca-report-library:latest`| The most recent release image pushed to a container registry. Pulling an image using the `:latest` tag [should be avoided.](https://vsupalov.com/docker-latest-tag/) |

See the [tags tab](https://hub.docker.com/r/cisagov/example/tags) on Docker
Hub for a list of all the supported tags.

## Volumes ##

| Mount point | Purpose |
There are no volumes for this container.
<!-- | Mount point | Purpose |
|-------------|----------------|
| `/var/log` | Log storage |
| `/home/cisa` | Log storage | -->

## Ports ##

There are no ports exposed by this container.

<!--
The following ports are exposed by this container:

| Port | Purpose |
Expand All @@ -165,30 +149,29 @@ The following ports are exposed by this container:

The sample [Docker composition](docker-compose.yml) publishes the
exposed port at 8080.
-->

## Environment variables ##

### Required ###
<!-- ### Required ###

There are no required environment variables.

<!--
| Name | Purpose | Default |
|-------|---------|---------|
| `REQUIRED_VARIABLE` | Describe its purpose. | `null` |
-->
| `` | | | -->

### Optional ###

| Name | Purpose | Default |
|-------|---------|---------|
| `ECHO_MESSAGE` | Sets the message echoed by this container. | `Hello World from Dockerfile` |
| `CISA_HOME` | Sets up as the working directory. | `/home/cisa` |
| `PCA_REPORT_TOOLS_SRC` | Set as the directory for the pca-report-library codebase. | `/usr/src/pca-report-tools` |

## Secrets ##

| Filename | Purpose |
There are no secrets for this container.
<!-- | Filename | Purpose |
|--------------|---------|
| `quote.txt` | Replaces the secret stored in the example library's package data. |
| `quote.txt` | Replaces the secret stored in the example library's package data. | -->

## Building from source ##

Expand All @@ -197,8 +180,8 @@ Build the image locally using this git repository as the [build context](https:/
```console
docker build \
--build-arg VERSION=0.0.1 \
--tag cisagov/example:0.0.1 \
https://github.com/cisagov/example.git#develop
--tag cisagov/pca-report-library:0.0.1 \
https://github.com/cisagov/pca-report-generator-docker.git#develop
```

## Cross-platform builds ##
Expand All @@ -211,8 +194,8 @@ Docker:
or the command line:

```console
git clone https://github.com/cisagov/example.git
cd example
git clone https://github.com/cisagov/pca-report-generator-docker.git
cd pca-report-generator-docker
```

1. Create the `Dockerfile-x` file with `buildx` platform support:
Expand All @@ -229,16 +212,9 @@ Docker:
--platform linux/amd64 \
--build-arg VERSION=0.0.1 \
--output type=docker \
--tag cisagov/example:0.0.1 .
--tag cisagov/pca-report-library:0.0.1 .
```

## New repositories from a skeleton ##

Please see our [Project Setup guide](https://github.com/cisagov/development-guide/tree/develop/project_setup)
for step-by-step instructions on how to start a new repository from
a skeleton. This will save you time and effort when configuring a
new repository!

## Contributing ##

We welcome contributions! Please see [`CONTRIBUTING.md`](CONTRIBUTING.md) for
Expand Down
18 changes: 4 additions & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,20 @@ secrets:
file: ./src/secrets/quote.txt

services:
example:
pca-report-library:
# Run the container normally
build:
# VERSION must be specified on the command line:
# e.g., --build-arg VERSION=0.0.1
context: .
dockerfile: Dockerfile
image: cisagov/example
image: cisagov/pca-report-library
ameliav marked this conversation as resolved.
Show resolved Hide resolved
init: true
restart: "no"
environment:
- ECHO_MESSAGE=Hello World from docker-compose!
ports:
- target: 8080
published: 8080
protocol: tcp
mode: host
secrets:
- source: quote_txt
target: quote.txt

example-version:
pca-report-library-version:
# Run the container to collect version information
image: cisagov/example
image: cisagov/pca-report-library
ameliav marked this conversation as resolved.
Show resolved Hide resolved
init: true
restart: "no"
command: --version
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Third-Party Libraries
import pytest

MAIN_SERVICE_NAME = "example"
MAIN_SERVICE_NAME = "pca-report-library"
VERSION_SERVICE_NAME = f"{MAIN_SERVICE_NAME}-version"


Expand Down
Loading