From b125c2c36102557de0ee35781fda6e4dbb1b2201 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 10 Feb 2024 11:51:48 +0300 Subject: [PATCH 01/71] Pillow runs on the latest version. --- requirements.txt | Bin 372 -> 358 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/requirements.txt b/requirements.txt index a69f01974a90e34b4bbbd3829eeb054a9d32a04f..fc52696fd725f5afa8682e60358871362cd309d5 100644 GIT binary patch delta 9 Qcmeyu^o(i3gNg6j02ycnQ~&?~ delta 23 dcmaFH^o41{172GOTLudTJqBYSHkx?99ROEk2F3sY From ced8d3310a35b4d047ae2b8302617b28fc21cb77 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 10 Feb 2024 11:52:11 +0300 Subject: [PATCH 02/71] Added 0.0.0.0 and localhost to allowed hosts --- studybud/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/studybud/settings.py b/studybud/settings.py index ec12aa7c0..70f369e3e 100644 --- a/studybud/settings.py +++ b/studybud/settings.py @@ -25,7 +25,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ["0.0.0.0", "127.0.0.1"] # Application definition From 61f2ac8f3aaba5d49441872a1ef9b08c0673aa9e Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 10 Feb 2024 11:52:41 +0300 Subject: [PATCH 03/71] first commit --- .dockerignore | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..5b3d79a85 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,34 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/go/build-context-dockerignore/ + +**/.DS_Store +**/__pycache__ +**/.venv +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md From 05d9b72361123d038b85ad3b583fd6ef369c6c49 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 10 Feb 2024 11:53:02 +0300 Subject: [PATCH 04/71] first commit --- Dockerfile | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ README.Docker.md | 22 ++++++++++++++++++++++ compose.yaml | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 Dockerfile create mode 100644 README.Docker.md create mode 100644 compose.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..38491510f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,49 @@ +# syntax=docker/dockerfile:1 + +# Comments are provided throughout this file to help you get started. +# If you need more help, visit the Dockerfile reference guide at +# https://docs.docker.com/go/dockerfile-reference/ + +ARG PYTHON_VERSION=3.11.4 +FROM python:${PYTHON_VERSION}-slim as base + +# Prevents Python from writing pyc files. +ENV PYTHONDONTWRITEBYTECODE=1 + +# Keeps Python from buffering stdout and stderr to avoid situations where +# the application crashes without emitting any logs due to buffering. +ENV PYTHONUNBUFFERED=1 + +WORKDIR /app + +# Create a non-privileged user that the app will run under. +# See https://docs.docker.com/go/dockerfile-user-best-practices/ +ARG UID=10001 +RUN adduser \ + --disabled-password \ + --gecos "" \ + --home "/nonexistent" \ + --shell "/sbin/nologin" \ + --no-create-home \ + --uid "${UID}" \ + appuser + +# Download dependencies as a separate step to take advantage of Docker's caching. +# Leverage a cache mount to /root/.cache/pip to speed up subsequent builds. +# Leverage a bind mount to requirements.txt to avoid having to copy them into +# into this layer. +RUN --mount=type=cache,target=/root/.cache/pip \ + --mount=type=bind,source=requirements.txt,target=requirements.txt \ + python -m pip install -r requirements.txt + +# Switch to the non-privileged user to run the application. +USER appuser + +# Copy the source code into the container. +COPY . . + +# Expose the port that the application listens on. +EXPOSE 8001 + +# Run the application. +CMD python manage.py runserver 0.0.0.0:8000 diff --git a/README.Docker.md b/README.Docker.md new file mode 100644 index 000000000..6dae561fa --- /dev/null +++ b/README.Docker.md @@ -0,0 +1,22 @@ +### Building and running your application + +When you're ready, start your application by running: +`docker compose up --build`. + +Your application will be available at http://localhost:8000. + +### Deploying your application to the cloud + +First, build your image, e.g.: `docker build -t myapp .`. +If your cloud uses a different CPU architecture than your development +machine (e.g., you are on a Mac M1 and your cloud provider is amd64), +you'll want to build the image for that platform, e.g.: +`docker build --platform=linux/amd64 -t myapp .`. + +Then, push it to your registry, e.g. `docker push myregistry.com/myapp`. + +Consult Docker's [getting started](https://docs.docker.com/go/get-started-sharing/) +docs for more detail on building and pushing. + +### References +* [Docker's Python guide](https://docs.docker.com/language/python/) \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 000000000..a2b39d6f5 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,49 @@ +# Comments are provided throughout this file to help you get started. +# If you need more help, visit the Docker compose reference guide at +# https://docs.docker.com/go/compose-spec-reference/ + +# Here the instructions define your application as a service called "server". +# This service is built from the Dockerfile in the current directory. +# You can add other services your application may depend on here, such as a +# database or a cache. For examples, see the Awesome Compose repository: +# https://github.com/docker/awesome-compose +services: + server: + build: + context: . + ports: + - 8000:8000 + +# The commented out section below is an example of how to define a PostgreSQL +# database that your application can use. `depends_on` tells Docker Compose to +# start the database before your application. The `db-data` volume persists the +# database data between container restarts. The `db-password` secret is used +# to set the database password. You must create `db/password.txt` and add +# a password of your choosing to it before running `docker compose up`. +# depends_on: +# db: +# condition: service_healthy +# db: +# image: postgres +# restart: always +# user: postgres +# secrets: +# - db-password +# volumes: +# - db-data:/var/lib/postgresql/data +# environment: +# - POSTGRES_DB=example +# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password +# expose: +# - 5432 +# healthcheck: +# test: [ "CMD", "pg_isready" ] +# interval: 10s +# timeout: 5s +# retries: 5 +# volumes: +# db-data: +# secrets: +# db-password: +# file: db/password.txt + From c1edd161127c25c7c66c9902670d35b9dab07f36 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Tue, 13 Feb 2024 20:19:24 +0300 Subject: [PATCH 05/71] CircleCI Commit --- .circleci/config.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 000000000..cbfecc7f1 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,32 @@ +# This config was automatically generated from your source code +# Stacks detected: deps:python:.,file:manage.py:. +version: 2.1 +orbs: + python: circleci/python@2 +jobs: + test-python: + # Install dependencies and run tests + docker: + - image: cimg/python:3.8-node + steps: + - checkout + - python/install-packages + - run: + name: Run tests + command: python manage.py test + deploy: + # This is an example deploy job, not actually used by the workflow + docker: + - image: cimg/base:stable + steps: + # Replace this with steps to deploy to users + - run: + name: deploy + command: '#e.g. ./deploy.sh' +workflows: + build-and-test: + jobs: + - test-python + # - deploy: + # requires: + # - test-python From c8347b89c7a8ba3444c9a25855831b5daf3a3e22 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Tue, 13 Feb 2024 20:51:19 +0300 Subject: [PATCH 06/71] Implemented circleci build --- .circleci/config.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index cbfecc7f1..4aa156a93 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,6 +4,21 @@ version: 2.1 orbs: python: circleci/python@2 jobs: + build: + docker: + - image: circleci/python:398 + steps: + - checkout + - python/install-packages + - run: + command: | + python3 -m venv venv + . venv/bin/activate + pip install -r requirements.txt + - save_cache: + key: deps1-{{ .Branch }}-{{ checksum "requirements.txt" }} + paths: + - "venv" test-python: # Install dependencies and run tests docker: @@ -12,8 +27,6 @@ jobs: - checkout - python/install-packages - run: - name: Run tests - command: python manage.py test deploy: # This is an example deploy job, not actually used by the workflow docker: From fbd0f7c0db07bb1c77c4d1083f8e7ccd9947d18d Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Tue, 13 Feb 2024 20:59:27 +0300 Subject: [PATCH 07/71] Amended python version --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4aa156a93..2c0b973a6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,7 +6,7 @@ orbs: jobs: build: docker: - - image: circleci/python:398 + - image: circleci/python:3.9.8 steps: - checkout - python/install-packages From 2b2cce5932fe9433d59f07a98411ec0a21689dad Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Tue, 13 Feb 2024 21:04:37 +0300 Subject: [PATCH 08/71] Redid build step --- .circleci/config.yml | 42 +++++++++--------------------------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2c0b973a6..610b0005d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,17 +1,14 @@ -# This config was automatically generated from your source code -# Stacks detected: deps:python:.,file:manage.py:. -version: 2.1 -orbs: - python: circleci/python@2 +version: 2 jobs: - build: + build: docker: - - image: circleci/python:3.9.8 + - image: circleci/python:3.6 steps: - checkout - - python/install-packages + - restore_cache: + key: deps1-{{ .Branch }}-{{ checksum "requirements.txt" }} - run: - command: | + command: | python3 -m venv venv . venv/bin/activate pip install -r requirements.txt @@ -19,27 +16,6 @@ jobs: key: deps1-{{ .Branch }}-{{ checksum "requirements.txt" }} paths: - "venv" - test-python: - # Install dependencies and run tests - docker: - - image: cimg/python:3.8-node - steps: - - checkout - - python/install-packages - - run: - deploy: - # This is an example deploy job, not actually used by the workflow - docker: - - image: cimg/base:stable - steps: - # Replace this with steps to deploy to users - - run: - name: deploy - command: '#e.g. ./deploy.sh' -workflows: - build-and-test: - jobs: - - test-python - # - deploy: - # requires: - # - test-python + - store_artifacts: + path: test-reports/ + destination: python_app \ No newline at end of file From a2de54dcd123d636b24e1e6f887615072b41341a Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Tue, 13 Feb 2024 21:11:03 +0300 Subject: [PATCH 09/71] Updated python version --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 610b0005d..55fc54861 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2 jobs: build: docker: - - image: circleci/python:3.6 + - image: circleci/python:3.11.4 steps: - checkout - restore_cache: From 73b38ae08ac5b19c50042bedb8d8b229501e4acd Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Tue, 13 Feb 2024 21:19:06 +0300 Subject: [PATCH 10/71] Changed to pyhon 3.11 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 55fc54861..70748f4c1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2 jobs: build: docker: - - image: circleci/python:3.11.4 + - image: circleci/python:3.11 steps: - checkout - restore_cache: From 5a4cc8a67bc232ea6ed1da738f6781c0cb2e3f72 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Tue, 13 Feb 2024 21:22:36 +0300 Subject: [PATCH 11/71] revert to python 3.6 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 70748f4c1..610b0005d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2 jobs: build: docker: - - image: circleci/python:3.11 + - image: circleci/python:3.6 steps: - checkout - restore_cache: From 072f6ea5c56c24365859629ff55f0126faeb31bc Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Wed, 14 Feb 2024 21:21:42 +0300 Subject: [PATCH 12/71] Added snyk security workflow --- .github/workflows/snyk-security.yml | 81 +++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 .github/workflows/snyk-security.yml diff --git a/.github/workflows/snyk-security.yml b/.github/workflows/snyk-security.yml new file mode 100644 index 000000000..4aafeaf12 --- /dev/null +++ b/.github/workflows/snyk-security.yml @@ -0,0 +1,81 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +# A sample workflow which sets up Snyk to analyze the full Snyk platform (Snyk Open Source, Snyk Code, +# Snyk Container and Snyk Infrastructure as Code) +# The setup installs the Snyk CLI - for more details on the possible commands +# check https://docs.snyk.io/snyk-cli/cli-reference +# The results of Snyk Code are then uploaded to GitHub Security Code Scanning +# +# In order to use the Snyk Action you will need to have a Snyk API token. +# More details in https://github.com/snyk/actions#getting-your-snyk-token +# or you can signup for free at https://snyk.io/login +# +# For more examples, including how to limit scans to only high-severity issues +# and fail PR checks, see https://github.com/snyk/actions/ + +name: Snyk Security + +on: + pull_request: + branches: ["master"] + +permissions: + contents: read + +jobs: + snyk: + permissions: + contents: read # for actions/checkout to fetch code + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results + actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Snyk CLI to check for security issues + # Snyk can be used to break the build when it detects security issues. + # In this case we want to upload the SAST issues to GitHub Code Scanning + uses: snyk/actions/setup@806182742461562b67788a64410098c9d9b96adb + + # For Snyk Open Source you must first set up the development environment for your application's dependencies + # For example for Node + #- uses: actions/setup-node@v3 + # with: + # node-version: 16 + - uses: actions/setup-python@v2 + with: + python-version: 3.11 + + + env: + # This is where you will need to introduce the Snyk API token created with your Snyk account + SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} + + # Runs Snyk Code (SAST) analysis and uploads result into GitHub. + # Use || true to not fail the pipeline + - name: Snyk Code test + run: snyk code test --sarif > snyk-code.sarif # || true + + # Runs Snyk Open Source (SCA) analysis and uploads result to Snyk. + - name: Snyk Open Source monitor + run: snyk monitor --all-projects + + # Runs Snyk Infrastructure as Code (IaC) analysis and uploads result to Snyk. + # Use || true to not fail the pipeline. + - name: Snyk IaC test and report + run: snyk iac test --report # || true + + # Build the docker image for testing + - name: Build a Docker image + run: docker build -t myapp . + # Runs Snyk Container (Container and SCA) analysis and uploads result to Snyk. + - name: Snyk Container monitor + run: snyk container monitor your/image-to-test --file=Dockerfile + + # Push the Snyk Code results into GitHub Code Scanning tab + - name: Upload result to GitHub Code Scanning + uses: github/codeql-action/upload-sarif@v2 + with: + sarif_file: snyk-code.sarif From e02f0c73eea29e61c87d69d6cd44d47b75e7ab3a Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Wed, 14 Feb 2024 21:33:49 +0300 Subject: [PATCH 13/71] Removed hyphen on uses on line 37 --- .github/workflows/snyk-security.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/snyk-security.yml b/.github/workflows/snyk-security.yml index 4aafeaf12..8b29bd144 100644 --- a/.github/workflows/snyk-security.yml +++ b/.github/workflows/snyk-security.yml @@ -33,8 +33,8 @@ jobs: actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - name: Set up Snyk CLI to check for security issues + uses: actions/checkout@v3 # Snyk can be used to break the build when it detects security issues. # In this case we want to upload the SAST issues to GitHub Code Scanning uses: snyk/actions/setup@806182742461562b67788a64410098c9d9b96adb From 0c85e0b60eb51d1032c6a7711d9a5136a3783d92 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Wed, 14 Feb 2024 21:46:11 +0300 Subject: [PATCH 14/71] Fixed indentation issue --- .github/workflows/snyk-security.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/snyk-security.yml b/.github/workflows/snyk-security.yml index 8b29bd144..b524e3bb3 100644 --- a/.github/workflows/snyk-security.yml +++ b/.github/workflows/snyk-security.yml @@ -39,14 +39,15 @@ jobs: # In this case we want to upload the SAST issues to GitHub Code Scanning uses: snyk/actions/setup@806182742461562b67788a64410098c9d9b96adb - # For Snyk Open Source you must first set up the development environment for your application's dependencies - # For example for Node - #- uses: actions/setup-node@v3 - # with: - # node-version: 16 - - uses: actions/setup-python@v2 - with: - python-version: 3.11 + # For Snyk Open Source, you must first set up the development environment for your application's dependencies + # For example for Node + #- uses: actions/setup-node@v3 + # with: + # node-version: 16 + - uses: actions/setup-python@v2 + with: + python-version: 3.11 + env: From 15757a4185f164818cebe5cb50ae174127d3b6a7 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Wed, 14 Feb 2024 21:50:40 +0300 Subject: [PATCH 15/71] Added hyphen on uses line 37 --- .github/workflows/snyk-security.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/snyk-security.yml b/.github/workflows/snyk-security.yml index b524e3bb3..637c7aef5 100644 --- a/.github/workflows/snyk-security.yml +++ b/.github/workflows/snyk-security.yml @@ -34,7 +34,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Set up Snyk CLI to check for security issues - uses: actions/checkout@v3 + - uses: actions/checkout@v3 # Snyk can be used to break the build when it detects security issues. # In this case we want to upload the SAST issues to GitHub Code Scanning uses: snyk/actions/setup@806182742461562b67788a64410098c9d9b96adb From d1cffcd08c4f4c590416ebc5de6442d6543b06ee Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Wed, 14 Feb 2024 21:54:09 +0300 Subject: [PATCH 16/71] Added uses on line 36 --- .github/workflows/snyk-security.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/snyk-security.yml b/.github/workflows/snyk-security.yml index 637c7aef5..e15213b13 100644 --- a/.github/workflows/snyk-security.yml +++ b/.github/workflows/snyk-security.yml @@ -33,8 +33,8 @@ jobs: actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status runs-on: ubuntu-latest steps: - - name: Set up Snyk CLI to check for security issues - uses: actions/checkout@v3 + - name: Set up Snyk CLI to check for security issues # Snyk can be used to break the build when it detects security issues. # In this case we want to upload the SAST issues to GitHub Code Scanning uses: snyk/actions/setup@806182742461562b67788a64410098c9d9b96adb From 5205d4d5156e5fa4ea27b8485f2e6128ff9d747c Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Wed, 14 Feb 2024 22:02:30 +0300 Subject: [PATCH 17/71] Added true statement on the Snyk code test --- .github/workflows/snyk-security.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/snyk-security.yml b/.github/workflows/snyk-security.yml index e15213b13..67686fe8c 100644 --- a/.github/workflows/snyk-security.yml +++ b/.github/workflows/snyk-security.yml @@ -57,7 +57,7 @@ jobs: # Runs Snyk Code (SAST) analysis and uploads result into GitHub. # Use || true to not fail the pipeline - name: Snyk Code test - run: snyk code test --sarif > snyk-code.sarif # || true + run: snyk code test --sarif > snyk-code.sarif || true # Runs Snyk Open Source (SCA) analysis and uploads result to Snyk. - name: Snyk Open Source monitor From 26ec2cac3bc0faf8932260d4817d2eb3619c27e3 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Wed, 14 Feb 2024 22:06:01 +0300 Subject: [PATCH 18/71] Authenticate with snyk --- .github/workflows/snyk-security.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/snyk-security.yml b/.github/workflows/snyk-security.yml index 67686fe8c..60d692fd9 100644 --- a/.github/workflows/snyk-security.yml +++ b/.github/workflows/snyk-security.yml @@ -53,6 +53,8 @@ jobs: env: # This is where you will need to introduce the Snyk API token created with your Snyk account SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} + - name: Authenticate with Snyk + run: snyk auth ${{ secrets.SNYK_TOKEN }} # Runs Snyk Code (SAST) analysis and uploads result into GitHub. # Use || true to not fail the pipeline @@ -66,7 +68,7 @@ jobs: # Runs Snyk Infrastructure as Code (IaC) analysis and uploads result to Snyk. # Use || true to not fail the pipeline. - name: Snyk IaC test and report - run: snyk iac test --report # || true + run: snyk iac test --report || true # Build the docker image for testing - name: Build a Docker image From 758d0902de309ca02e07680745da1ef77585f3dd Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Wed, 14 Feb 2024 22:07:48 +0300 Subject: [PATCH 19/71] fixed indentation issue --- .github/workflows/snyk-security.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/snyk-security.yml b/.github/workflows/snyk-security.yml index 60d692fd9..9052bac10 100644 --- a/.github/workflows/snyk-security.yml +++ b/.github/workflows/snyk-security.yml @@ -53,8 +53,8 @@ jobs: env: # This is where you will need to introduce the Snyk API token created with your Snyk account SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} - - name: Authenticate with Snyk - run: snyk auth ${{ secrets.SNYK_TOKEN }} + - name: Authenticate with Snyk + run: snyk auth ${{ secrets.SNYK_TOKEN }} # Runs Snyk Code (SAST) analysis and uploads result into GitHub. # Use || true to not fail the pipeline From 003288219ae8756665c84be18263c1fa53929374 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Wed, 14 Feb 2024 22:11:25 +0300 Subject: [PATCH 20/71] Added debug flag to see issues on open source monitoring. --- .github/workflows/snyk-security.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/snyk-security.yml b/.github/workflows/snyk-security.yml index 9052bac10..2082e468d 100644 --- a/.github/workflows/snyk-security.yml +++ b/.github/workflows/snyk-security.yml @@ -63,7 +63,7 @@ jobs: # Runs Snyk Open Source (SCA) analysis and uploads result to Snyk. - name: Snyk Open Source monitor - run: snyk monitor --all-projects + run: snyk monitor --all-projects --debug # Runs Snyk Infrastructure as Code (IaC) analysis and uploads result to Snyk. # Use || true to not fail the pipeline. From 702f4cacb5b9d3bda6effffa901177c56b65e92a Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Wed, 14 Feb 2024 22:14:58 +0300 Subject: [PATCH 21/71] get python dependencies --- .github/workflows/snyk-security.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/snyk-security.yml b/.github/workflows/snyk-security.yml index 2082e468d..0ae4c4b28 100644 --- a/.github/workflows/snyk-security.yml +++ b/.github/workflows/snyk-security.yml @@ -60,6 +60,9 @@ jobs: # Use || true to not fail the pipeline - name: Snyk Code test run: snyk code test --sarif > snyk-code.sarif || true + + - name: Get python dependencies + run: pip install -r requirements.txt # Runs Snyk Open Source (SCA) analysis and uploads result to Snyk. - name: Snyk Open Source monitor From 45104f6908067a77ed5d16c05b1fae63a339a512 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Wed, 14 Feb 2024 22:17:15 +0300 Subject: [PATCH 22/71] remove debug flag on open source monitor --- .github/workflows/snyk-security.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/snyk-security.yml b/.github/workflows/snyk-security.yml index 0ae4c4b28..1500944ac 100644 --- a/.github/workflows/snyk-security.yml +++ b/.github/workflows/snyk-security.yml @@ -66,7 +66,7 @@ jobs: # Runs Snyk Open Source (SCA) analysis and uploads result to Snyk. - name: Snyk Open Source monitor - run: snyk monitor --all-projects --debug + run: snyk monitor --all-projects # Runs Snyk Infrastructure as Code (IaC) analysis and uploads result to Snyk. # Use || true to not fail the pipeline. From fff3d901f6d1560d85b42874e3de8c908d64ea83 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Wed, 14 Feb 2024 22:17:32 +0300 Subject: [PATCH 23/71] Removed IaC implementation --- .github/workflows/snyk-security.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/snyk-security.yml b/.github/workflows/snyk-security.yml index 1500944ac..cb49c8a25 100644 --- a/.github/workflows/snyk-security.yml +++ b/.github/workflows/snyk-security.yml @@ -70,8 +70,8 @@ jobs: # Runs Snyk Infrastructure as Code (IaC) analysis and uploads result to Snyk. # Use || true to not fail the pipeline. - - name: Snyk IaC test and report - run: snyk iac test --report || true + # - name: Snyk IaC test and report + # run: snyk iac test --report || true # Build the docker image for testing - name: Build a Docker image From 6d120c9b6592176ed2d67b2b044ea5c847a93d88 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Wed, 14 Feb 2024 22:20:55 +0300 Subject: [PATCH 24/71] Changed image name --- .github/workflows/snyk-security.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/snyk-security.yml b/.github/workflows/snyk-security.yml index cb49c8a25..f79bd9b86 100644 --- a/.github/workflows/snyk-security.yml +++ b/.github/workflows/snyk-security.yml @@ -78,7 +78,7 @@ jobs: run: docker build -t myapp . # Runs Snyk Container (Container and SCA) analysis and uploads result to Snyk. - name: Snyk Container monitor - run: snyk container monitor your/image-to-test --file=Dockerfile + run: snyk container monitor chat-room-server --file=Dockerfile # Push the Snyk Code results into GitHub Code Scanning tab - name: Upload result to GitHub Code Scanning From 6c20417a1f3ab334b4ee6f40f87e98b833857151 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Wed, 14 Feb 2024 22:23:15 +0300 Subject: [PATCH 25/71] Changed container name --- .github/workflows/snyk-security.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/snyk-security.yml b/.github/workflows/snyk-security.yml index f79bd9b86..f20a7baf4 100644 --- a/.github/workflows/snyk-security.yml +++ b/.github/workflows/snyk-security.yml @@ -78,7 +78,7 @@ jobs: run: docker build -t myapp . # Runs Snyk Container (Container and SCA) analysis and uploads result to Snyk. - name: Snyk Container monitor - run: snyk container monitor chat-room-server --file=Dockerfile + run: snyk container monitor myapp --file=Dockerfile # Push the Snyk Code results into GitHub Code Scanning tab - name: Upload result to GitHub Code Scanning From 1c5c27f50457d3606949b56dc8b69cdbd9ed036d Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 4 May 2024 13:55:48 +0300 Subject: [PATCH 26/71] Docker image scan using Docker scout --- .github/workflows/container-scan.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/container-scan.yml diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml new file mode 100644 index 000000000..b706dece7 --- /dev/null +++ b/.github/workflows/container-scan.yml @@ -0,0 +1,28 @@ +name: Docker scout CVE scan + +on: + pull_request: + branches: ["master"] +jobs: + scan-docker-image-for-vulnerabilities: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Build docker image + run: docker build . -t chat-room:latest + + - name: Authenticate to Docker hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PAT }} + + - name: Check for CVEs on Docker scout + uses: docker/scout-action@v1 + with: + command: cves + image: chat-room:latest + ignore-unchanged: true + only-severities: critical,high \ No newline at end of file From ed5ed67cd34bd6d03ac576553284660f45d4bb00 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 4 May 2024 13:56:50 +0300 Subject: [PATCH 27/71] removed snyk container step --- .github/workflows/snyk-security.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/snyk-security.yml b/.github/workflows/snyk-security.yml index f20a7baf4..08ccb1a06 100644 --- a/.github/workflows/snyk-security.yml +++ b/.github/workflows/snyk-security.yml @@ -73,13 +73,6 @@ jobs: # - name: Snyk IaC test and report # run: snyk iac test --report || true - # Build the docker image for testing - - name: Build a Docker image - run: docker build -t myapp . - # Runs Snyk Container (Container and SCA) analysis and uploads result to Snyk. - - name: Snyk Container monitor - run: snyk container monitor myapp --file=Dockerfile - # Push the Snyk Code results into GitHub Code Scanning tab - name: Upload result to GitHub Code Scanning uses: github/codeql-action/upload-sarif@v2 From 51c754732b29e58bd80143a30d0c53ad1df10541 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 4 May 2024 14:04:35 +0300 Subject: [PATCH 28/71] provide recommendations to fix vulnerabilities --- .github/workflows/container-scan.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml index b706dece7..220b42a95 100644 --- a/.github/workflows/container-scan.yml +++ b/.github/workflows/container-scan.yml @@ -25,4 +25,11 @@ jobs: command: cves image: chat-room:latest ignore-unchanged: true - only-severities: critical,high \ No newline at end of file + only-severities: critical,high + + - name: Provide recommendations + uses: docker/scout-action@v1 + with: + command: reccomendations + image: chat-room:latest + ignore-unchanged: true \ No newline at end of file From dd0fe235ee86c6dabd36a9bfba2d868eb11d742f Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 4 May 2024 14:06:37 +0300 Subject: [PATCH 29/71] fix typo for recommendations --- .github/workflows/container-scan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml index 220b42a95..db7830f4e 100644 --- a/.github/workflows/container-scan.yml +++ b/.github/workflows/container-scan.yml @@ -30,6 +30,6 @@ jobs: - name: Provide recommendations uses: docker/scout-action@v1 with: - command: reccomendations + command: recomendations image: chat-room:latest ignore-unchanged: true \ No newline at end of file From 46545c276987ca8cc6a3b19eaa28dfa4af49922e Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 4 May 2024 14:10:10 +0300 Subject: [PATCH 30/71] Update recommendations --- .github/workflows/container-scan.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml index db7830f4e..f18a39aea 100644 --- a/.github/workflows/container-scan.yml +++ b/.github/workflows/container-scan.yml @@ -31,5 +31,4 @@ jobs: uses: docker/scout-action@v1 with: command: recomendations - image: chat-room:latest - ignore-unchanged: true \ No newline at end of file + image: chat-room:latest \ No newline at end of file From ac78e4140034129966c79b80773fd58c368675ab Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 4 May 2024 14:12:39 +0300 Subject: [PATCH 31/71] removed image name --- .github/workflows/container-scan.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml index f18a39aea..066ee4f7f 100644 --- a/.github/workflows/container-scan.yml +++ b/.github/workflows/container-scan.yml @@ -30,5 +30,4 @@ jobs: - name: Provide recommendations uses: docker/scout-action@v1 with: - command: recomendations - image: chat-room:latest \ No newline at end of file + command: recomendations \ No newline at end of file From 12d1b113006c78da6f61db15438e1faca4d9fee0 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 4 May 2024 14:14:56 +0300 Subject: [PATCH 32/71] changed spelling for recommendations --- .github/workflows/container-scan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml index 066ee4f7f..ffeb98bf3 100644 --- a/.github/workflows/container-scan.yml +++ b/.github/workflows/container-scan.yml @@ -30,4 +30,4 @@ jobs: - name: Provide recommendations uses: docker/scout-action@v1 with: - command: recomendations \ No newline at end of file + command: recommendations \ No newline at end of file From 9216c4b0195eb7771140ab86fc0c5caca564ee75 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 4 May 2024 14:24:33 +0300 Subject: [PATCH 33/71] Changed base image from 3.11.4 to 3.11.8 slim --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 38491510f..ea77fdfb5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ # If you need more help, visit the Dockerfile reference guide at # https://docs.docker.com/go/dockerfile-reference/ -ARG PYTHON_VERSION=3.11.4 +ARG PYTHON_VERSION=3.11.8 FROM python:${PYTHON_VERSION}-slim as base # Prevents Python from writing pyc files. From aa1d188b853f3df0783f7a15496377f338117cf3 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 4 May 2024 14:28:17 +0300 Subject: [PATCH 34/71] change docker image to 3.12.2 from 3.11.8 slim --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ea77fdfb5..b34238eb2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ # If you need more help, visit the Dockerfile reference guide at # https://docs.docker.com/go/dockerfile-reference/ -ARG PYTHON_VERSION=3.11.8 +ARG PYTHON_VERSION=3.12.2 FROM python:${PYTHON_VERSION}-slim as base # Prevents Python from writing pyc files. From 4dedc3f94a5deb4d2e20eb926243fee697d04999 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 4 May 2024 15:10:18 +0300 Subject: [PATCH 35/71] Changed image version from 3.12.2-slim to 3.12-slim-bookworm --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b34238eb2..62e038b05 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,8 @@ # If you need more help, visit the Dockerfile reference guide at # https://docs.docker.com/go/dockerfile-reference/ -ARG PYTHON_VERSION=3.12.2 -FROM python:${PYTHON_VERSION}-slim as base +ARG PYTHON_VERSION=3.12 +FROM python:${PYTHON_VERSION}-slim-bookworm as base # Prevents Python from writing pyc files. ENV PYTHONDONTWRITEBYTECODE=1 From ceea830d63b9b85a2e92c21a2fee111bf57d6f30 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 4 May 2024 15:23:38 +0300 Subject: [PATCH 36/71] Add workflow for OWASP ZAP baseline scan --- .github/workflows/zap-baseline-scan.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/zap-baseline-scan.yml diff --git a/.github/workflows/zap-baseline-scan.yml b/.github/workflows/zap-baseline-scan.yml new file mode 100644 index 000000000..376ed1356 --- /dev/null +++ b/.github/workflows/zap-baseline-scan.yml @@ -0,0 +1,24 @@ +name: Perform ZAP baseline scan (Dynamic Application Security Testing) + +on: + pull_request: + branches: ["master"] +jobs: + perform-baseline-scan: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Build docker image + run: docker build -t chat-room:latest . + + - name: Run docker image + run: docker run -dp 8000:8000 -rm chat-room:latest + + - name: Set up OWASP ZAP baseline scan + uses: zaproxy/action-baseline@v0.12.0 + with: + target: 'http://localhost:8000' + + From b7647c536590bc26afabd7cddb8d61025b0e4a8f Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 4 May 2024 15:28:36 +0300 Subject: [PATCH 37/71] removed --rm flag --- .github/workflows/zap-baseline-scan.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/zap-baseline-scan.yml b/.github/workflows/zap-baseline-scan.yml index 376ed1356..70abb84d9 100644 --- a/.github/workflows/zap-baseline-scan.yml +++ b/.github/workflows/zap-baseline-scan.yml @@ -14,11 +14,11 @@ jobs: run: docker build -t chat-room:latest . - name: Run docker image - run: docker run -dp 8000:8000 -rm chat-room:latest + run: docker run -dp 8000:8000 --rm chat-room:latest - name: Set up OWASP ZAP baseline scan uses: zaproxy/action-baseline@v0.12.0 with: target: 'http://localhost:8000' - + From 0f41378222076c133d062a88fb214f2fe40b404e Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 4 May 2024 15:28:52 +0300 Subject: [PATCH 38/71] removed --rm flag --- .github/workflows/zap-baseline-scan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/zap-baseline-scan.yml b/.github/workflows/zap-baseline-scan.yml index 70abb84d9..aedebb7ab 100644 --- a/.github/workflows/zap-baseline-scan.yml +++ b/.github/workflows/zap-baseline-scan.yml @@ -14,7 +14,7 @@ jobs: run: docker build -t chat-room:latest . - name: Run docker image - run: docker run -dp 8000:8000 --rm chat-room:latest + run: docker run -dp 8000:8000 chat-room:latest - name: Set up OWASP ZAP baseline scan uses: zaproxy/action-baseline@v0.12.0 From 37ff9d1e1908d466d7ed90c8bc8f98a17a4cdf24 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 4 May 2024 16:12:34 +0300 Subject: [PATCH 39/71] first commit --- .../build-and-push-to-docker-hub.yml | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/build-and-push-to-docker-hub.yml diff --git a/.github/workflows/build-and-push-to-docker-hub.yml b/.github/workflows/build-and-push-to-docker-hub.yml new file mode 100644 index 000000000..771527b5d --- /dev/null +++ b/.github/workflows/build-and-push-to-docker-hub.yml @@ -0,0 +1,31 @@ +name: Build and push image to Docker Hub + +on: + push: + branches: + - master + +jobs: + build-and-push-image-to-docker-hub: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Buildx + uses: docker/setup-buildx-action@v3 + + - name: Authenticate to Docker Hub + uses: docker/login-action@v3 + with: + registry: docker.io + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PAT }} + + - name: Build and push image to Docker hub + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/chat-room:latest \ No newline at end of file From fa2b36b7adddb00c532c354e988717eabc6a655c Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 11 May 2024 20:43:55 +0300 Subject: [PATCH 40/71] GCP infrastructure setup --- .../shell_scripts/decrypt_service_account.sh | 4 ++ .github/workflows/test-gcp-infra-setup.yml | 47 ++++++++++++++++++ terraform/backend.tf | 9 ++++ terraform/key.json.gpg | Bin 0 -> 1743 bytes terraform/main.tf | 31 ++++++++++++ terraform/variables.tf | 15 ++++++ 6 files changed, 106 insertions(+) create mode 100644 .github/shell_scripts/decrypt_service_account.sh create mode 100644 .github/workflows/test-gcp-infra-setup.yml create mode 100644 terraform/backend.tf create mode 100644 terraform/key.json.gpg create mode 100644 terraform/main.tf create mode 100644 terraform/variables.tf diff --git a/.github/shell_scripts/decrypt_service_account.sh b/.github/shell_scripts/decrypt_service_account.sh new file mode 100644 index 000000000..9f6dc9f28 --- /dev/null +++ b/.github/shell_scripts/decrypt_service_account.sh @@ -0,0 +1,4 @@ +#!/bin/sh +file_name=${GITHUB_WORKSPACE}/gcp/key.json.gpg + +gpg --quiet --batch --yes --decrypt --passphrase="$GCP_SERVICE_ACCOUNT_PASSPHRASE" --output ${GITHUB_WORKSPACE}/gcp/key.json $file_name \ No newline at end of file diff --git a/.github/workflows/test-gcp-infra-setup.yml b/.github/workflows/test-gcp-infra-setup.yml new file mode 100644 index 000000000..09f2db802 --- /dev/null +++ b/.github/workflows/test-gcp-infra-setup.yml @@ -0,0 +1,47 @@ +name: GCP tests + +on: + pull_request: + branches: + - master + +jobs: + run-gcp-tests: + runs-on: ubuntu-latest + + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Terraform + uses: hashicorp/setup-terraform@v1 + with: + terraform_version: 1.7.5 + + - name: Initialize Terraform + env: + AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }} + AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }} + run: terraform -chdir=${GITHUB_WORKSPACE}/gcp init -backend-config="access_key=$AWS_ACCESS_KEY" -backend-config="secret_key=$AWS_SECRET_KEY" + + - name: Check formatting + run: terraform -chdir=${GITHUB_WORKSPACE}/gcp fmt -check + + - name: Check for bugs + run: terraform -chdir=${GITHUB_WORKSPACE}/gcp validate + + - name: Decrypt service account key + env: + GCP_SERVICE_ACCOUNT_PASSPHRASE: ${{ secrets.GCP_SERVICE_ACCOUNT_PASSPHRASE }} + run: | + chmod +x ${GITHUB_WORKSPACE}/.github/workflows/shell_scripts/decrypt_service_account.sh + bash ${GITHUB_WORKSPACE}/.github/workflows/shell_scripts/decrypt_service_account.sh + + - name: Does your configuration make sense? + env: + GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} + run: | + terraform -chdir=${GITHUB_WORKSPACE}/gcp plan \ + -var path_to_gcp_service_account="${GITHUB_WORKSPACE}/gcp/key.json" \ + -var project_id=$GCP_PROJECT_ID \ No newline at end of file diff --git a/terraform/backend.tf b/terraform/backend.tf new file mode 100644 index 000000000..b16ad5758 --- /dev/null +++ b/terraform/backend.tf @@ -0,0 +1,9 @@ +terraform { + + backend "s3" { + bucket = "terraform-state-bucket-270420241723" + key = "global/gcp/terraform.tfstate" + region = "us-east-2" + encrypt = true + } +} \ No newline at end of file diff --git a/terraform/key.json.gpg b/terraform/key.json.gpg new file mode 100644 index 0000000000000000000000000000000000000000..e0e109240a5b99d530fdfafe5986c6f1f0cefce7 GIT binary patch literal 1743 zcmV;=1~B=I4Fm}T0_WtmW9u&Zy8qJZ0b0dHwaNmr^W#*LYYxcq2 zA*JJs@2P|Fe~ZwpS6c=PBnB8z!#K9DxxSI?4~yeFIlFKGc#F#WG*dh!5xe$zhnvXI z`jmT$o7RsYh7?9*v@PY{Dq4Cp+BY=Rt(R8O|F?*}nL~wxH-x8fbyv0Y0jYR1Y`2{9 zG4I1<~n}WaK;bc zcQ^o)7)wWkcpOY1e%pRdN4Nh+VtT-stnJqg#V?Yj0zY*YtKa`TQFQ^ z*#}eUxazFe<*?pQhEe86Y;IJ4+1PxheD2-gh?`V-YGE1?JK_z&B9-aW%{5HU9Xzyz z#xO#k8-r99#`nP8?u#Ec9{Blz(%|bOA*oB4ioOg7loP8&$#x8Z2SejuzXD9xg_2YTz0wWPAo9rB&=0!zzvb zYUECz=F#Tk<(M!gD9R?`n}G)?%P4WOqx+X+tUZumq3|&L3gLWDnoo`QB2wrfiks6i zUc^rY== z^2~V4Yy>w&>2sB8){N^XbZVMh3+VOP{VUrWC+NvKxDFRvm~!)!>7Iqa_>b3WjbYP3 zLF+e68}iKlW{JSoxPF9agt_F5^vMZTR0Hzz}Q;;?oXuW2mDU~fEjjw;9#w9 zdsly37_7?D0RK@HzB^n4)S)TpW5<}C|PP{OxR3&a-&Ih8CFc%R20kPY420Kl`j}>Krj8F{%`TA#@`c zAB-0+ofIVR4>I>KQS9kh6G>qW0${rsrD_0SZz&2OGx)+r5s-KKwELI*P(BjsGX(Ot zy`+qchbfP!Rh3P;634asl8oMz{U7hX?i_2~D6Fw{`Bn6Zty-kmqL^ZLpM04!MmH>Y z4Kb--d2lo0zBGnbJ=Wj)@YN1*R%yiTOpVL;_%mbwrrdZ9u)OkFv>t#^xa8cHdNNh) z_m@9xYdr9pjuN&R^gD&d_Hi>P{fUqRg4k)Sd`{7$%KtQPsppXOu)mjZg_H$!iCo~S zZ@hx2o?02hx!GV9$e7$24%&<~paxPErf2|~5Pp4SEgP$rsY6ufYo=630M zsz${ShdP%Nwd*~XnPG6aj9$)x72*hJX`^zwnLq0>h0zFv&aAb4TJ#AX#_D*_35F%+ lr?x8P4vu`y92i_|2aXX^udI9N+b(h^Uazj$n)F9l>fGT!cZL7} literal 0 HcmV?d00001 diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 000000000..9b568d41d --- /dev/null +++ b/terraform/main.tf @@ -0,0 +1,31 @@ +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = "5.28.0" + } + } +} + +provider "google" { + project = var.project_id + region = var.region + credentials = file(var.path_to_gcp_service_account) +} + +resource "google_cloud_run_v2_service" "chat-room-deployment" { + name = "chat-room-deployment" + location = var.region + ingress = "INGRESS_TRAFFIC_ALL" + template { + containers { + image = "docker.io/kiiru4reals/chat-room:latest" + resources { + limits = { + cpu = "2" + memory = "2048Mi" + } + } + } + } +} \ No newline at end of file diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 000000000..c14f778ad --- /dev/null +++ b/terraform/variables.tf @@ -0,0 +1,15 @@ +variable "project_id" { + description = "Project ID for GCP project" + type = string +} + +variable "region" { + description = "Region for GCP project" + type = string + default = "us-central1" +} + +variable "path_to_gcp_service_account" { + description = "Path to the GCP service account credentials" + type = string +} \ No newline at end of file From 4900c6808ba6b0687bc8c37fc2197e5e29603eea Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 11 May 2024 20:44:35 +0300 Subject: [PATCH 41/71] Refactored code to make trigger to make it look nice. --- .github/workflows/container-scan.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml index ffeb98bf3..f038d9394 100644 --- a/.github/workflows/container-scan.yml +++ b/.github/workflows/container-scan.yml @@ -2,7 +2,8 @@ name: Docker scout CVE scan on: pull_request: - branches: ["master"] + branches: + - master jobs: scan-docker-image-for-vulnerabilities: runs-on: ubuntu-latest From e3ff523bfe1352ff4e3ee2bfcd21834849bbcc6f Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 11 May 2024 20:50:13 +0300 Subject: [PATCH 42/71] Changed terraform directory --- .github/shell_scripts/decrypt_service_account.sh | 4 ++-- .github/workflows/test-gcp-infra-setup.yml | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/shell_scripts/decrypt_service_account.sh b/.github/shell_scripts/decrypt_service_account.sh index 9f6dc9f28..8110e0bb6 100644 --- a/.github/shell_scripts/decrypt_service_account.sh +++ b/.github/shell_scripts/decrypt_service_account.sh @@ -1,4 +1,4 @@ #!/bin/sh -file_name=${GITHUB_WORKSPACE}/gcp/key.json.gpg +file_name=${GITHUB_WORKSPACE}/terraform/key.json.gpg -gpg --quiet --batch --yes --decrypt --passphrase="$GCP_SERVICE_ACCOUNT_PASSPHRASE" --output ${GITHUB_WORKSPACE}/gcp/key.json $file_name \ No newline at end of file +gpg --quiet --batch --yes --decrypt --passphrase="$GCP_SERVICE_ACCOUNT_PASSPHRASE" --output ${GITHUB_WORKSPACE}/terraform/key.json $file_name \ No newline at end of file diff --git a/.github/workflows/test-gcp-infra-setup.yml b/.github/workflows/test-gcp-infra-setup.yml index 09f2db802..7aaf313f0 100644 --- a/.github/workflows/test-gcp-infra-setup.yml +++ b/.github/workflows/test-gcp-infra-setup.yml @@ -23,13 +23,13 @@ jobs: env: AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }} AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }} - run: terraform -chdir=${GITHUB_WORKSPACE}/gcp init -backend-config="access_key=$AWS_ACCESS_KEY" -backend-config="secret_key=$AWS_SECRET_KEY" + run: terraform -chdir=${GITHUB_WORKSPACE}/terraform init -backend-config="access_key=$AWS_ACCESS_KEY" -backend-config="secret_key=$AWS_SECRET_KEY" - name: Check formatting - run: terraform -chdir=${GITHUB_WORKSPACE}/gcp fmt -check + run: terraform -chdir=${GITHUB_WORKSPACE}/terraform fmt -check - name: Check for bugs - run: terraform -chdir=${GITHUB_WORKSPACE}/gcp validate + run: terraform -chdir=${GITHUB_WORKSPACE}/terraform validate - name: Decrypt service account key env: @@ -42,6 +42,6 @@ jobs: env: GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} run: | - terraform -chdir=${GITHUB_WORKSPACE}/gcp plan \ - -var path_to_gcp_service_account="${GITHUB_WORKSPACE}/gcp/key.json" \ + terraform -chdir=${GITHUB_WORKSPACE}/terraform plan \ + -var path_to_gcp_service_account="${GITHUB_WORKSPACE}/terraform/key.json" \ -var project_id=$GCP_PROJECT_ID \ No newline at end of file From baf431c2f196723ead908be927ab1a16bc253805 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 11 May 2024 20:52:13 +0300 Subject: [PATCH 43/71] refactor shell script location --- .github/{ => workflows}/shell_scripts/decrypt_service_account.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{ => workflows}/shell_scripts/decrypt_service_account.sh (100%) diff --git a/.github/shell_scripts/decrypt_service_account.sh b/.github/workflows/shell_scripts/decrypt_service_account.sh similarity index 100% rename from .github/shell_scripts/decrypt_service_account.sh rename to .github/workflows/shell_scripts/decrypt_service_account.sh From e26e053549f65d9aeb1368e5a000e3f65651f03e Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 11 May 2024 23:31:17 +0300 Subject: [PATCH 44/71] updated config to match master configs --- terraform/main.tf | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index 9b568d41d..30b16b4b9 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -20,12 +20,48 @@ resource "google_cloud_run_v2_service" "chat-room-deployment" { template { containers { image = "docker.io/kiiru4reals/chat-room:latest" + ports { + name = "http1" + container_port = 8000 + } resources { limits = { - cpu = "2" - memory = "2048Mi" + cpu = "1" + memory = "512Mi" } + startup_cpu_boost = false + cpu_idle = false } } + scaling { + min_instance_count = 0 + max_instance_count = 1 + + } + timeout = "60.0s" + max_instance_request_concurrency = 5 + execution_environment = "EXECUTION_ENVIRONMENT_GEN1" } -} \ No newline at end of file +} + +resource "google_cloud_run_v2_service_iam_member" "allow-public-access" { + location = google_cloud_run_v2_service.chat-room-deployment.location + name = google_cloud_run_v2_service.chat-room-deployment.name + role = "roles/run.invoker" + member = "allUsers" + +} + +# Set up domain mapping manually +# data "google_project" "project_info" {} + +# resource "google_" "chatroom-kiiru-maina-com" { +# name = "chatroom.kiirumaina.com" +# location = google_cloud_run_v2_service.chat-room-deployment.location +# metadata { +# namespace = data.google_project.project_info.project_id +# } +# spec { +# route_name = google_cloud_run_v2_service.chat-room-deployment.name +# } +# } \ No newline at end of file From c9eec81d3c6cfb9ef5cc1d5decdcc440170f8698 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 11 May 2024 23:41:32 +0300 Subject: [PATCH 45/71] Added chatroom.kiirumaina.com to allowed hosts --- studybud/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/studybud/settings.py b/studybud/settings.py index 70f369e3e..6f29daf45 100644 --- a/studybud/settings.py +++ b/studybud/settings.py @@ -25,7 +25,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = ["0.0.0.0", "127.0.0.1"] +ALLOWED_HOSTS = ["0.0.0.0", "127.0.0.1", "chatroom.kiirumaina.com"] # Application definition From ec41088b070d54a25b48ed1fc74344cdd318b403 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Thu, 26 Dec 2024 13:59:39 +0300 Subject: [PATCH 46/71] Add git-leaks pre-commit hook --- .pre-commit-config.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..9a38dba73 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,5 @@ +repos: + - repo: https://github.com/gitleaks/gitleaks + rev: v8.22.0 + hooks: + - id: gitleaks \ No newline at end of file From 0114d7a44a697a7e90900ed36589d2145ce3d254 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Thu, 26 Dec 2024 15:00:56 +0300 Subject: [PATCH 47/71] Add venv to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..39a6482fa --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +chat-room-env/ \ No newline at end of file From 6dc353ba188b8b727f84159cfe0bc289fc6a9d72 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Fri, 14 Mar 2025 21:50:26 +0300 Subject: [PATCH 48/71] Get commit SHA and pin artifact --- .github/workflows/build-and-push-to-docker-hub.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-and-push-to-docker-hub.yml b/.github/workflows/build-and-push-to-docker-hub.yml index 771527b5d..319ecf3e6 100644 --- a/.github/workflows/build-and-push-to-docker-hub.yml +++ b/.github/workflows/build-and-push-to-docker-hub.yml @@ -21,6 +21,9 @@ jobs: registry: docker.io username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PAT }} + + - name: Get commit SHA # This retrieves a shortened version of the commit SHA and stores is as an environment variable + run: echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - name: Build and push image to Docker hub uses: docker/build-push-action@v2 @@ -28,4 +31,4 @@ jobs: context: . file: ./Dockerfile push: true - tags: ${{ secrets.DOCKER_USERNAME }}/chat-room:latest \ No newline at end of file + tags: ${{ secrets.DOCKER_USERNAME }}/chat-room:${{env.COMMIT_SHA}} ${{secrets.DOCKER_USERNAME}}/chat-room:latest # Second tag makes it easy to pull the image to deployment environment \ No newline at end of file From 86b90eaa27e998d8732c9096935c307e80642efb Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Fri, 14 Mar 2025 21:59:38 +0300 Subject: [PATCH 49/71] Add tags attribute twice --- .github/workflows/build-and-push-to-docker-hub.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-and-push-to-docker-hub.yml b/.github/workflows/build-and-push-to-docker-hub.yml index 319ecf3e6..7e3e6a0a6 100644 --- a/.github/workflows/build-and-push-to-docker-hub.yml +++ b/.github/workflows/build-and-push-to-docker-hub.yml @@ -31,4 +31,5 @@ jobs: context: . file: ./Dockerfile push: true - tags: ${{ secrets.DOCKER_USERNAME }}/chat-room:${{env.COMMIT_SHA}} ${{secrets.DOCKER_USERNAME}}/chat-room:latest # Second tag makes it easy to pull the image to deployment environment \ No newline at end of file + tags: ${{ secrets.DOCKER_USERNAME }}/chat-room:${{env.COMMIT_SHA}} + tags: ${{secrets.DOCKER_USERNAME}}/chat-room:latest # Second tag makes it easy to pull the image to deployment environment \ No newline at end of file From 95e084dc02f5f0c7c192deba1fe1d1b992dea690 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Fri, 14 Mar 2025 22:16:13 +0300 Subject: [PATCH 50/71] Removing extra tag attribute and made it a list on the first tag attribute. --- .github/workflows/build-and-push-to-docker-hub.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-push-to-docker-hub.yml b/.github/workflows/build-and-push-to-docker-hub.yml index 7e3e6a0a6..eec5dccb9 100644 --- a/.github/workflows/build-and-push-to-docker-hub.yml +++ b/.github/workflows/build-and-push-to-docker-hub.yml @@ -31,5 +31,6 @@ jobs: context: . file: ./Dockerfile push: true - tags: ${{ secrets.DOCKER_USERNAME }}/chat-room:${{env.COMMIT_SHA}} - tags: ${{secrets.DOCKER_USERNAME}}/chat-room:latest # Second tag makes it easy to pull the image to deployment environment \ No newline at end of file + tags: | # Second tag makes it easy to pull the image to deployment environment + ${{ secrets.DOCKER_USERNAME }}/chat-room:${{env.COMMIT_SHA}} + ${{secrets.DOCKER_USERNAME}}/chat-room:latest \ No newline at end of file From 16e6774db30c1c0257d18b183f1076561a4b938c Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 15 Mar 2025 00:27:11 +0300 Subject: [PATCH 51/71] Generate SBOM on Docker security scan --- .github/workflows/container-scan.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml index f038d9394..4e486ac7a 100644 --- a/.github/workflows/container-scan.yml +++ b/.github/workflows/container-scan.yml @@ -11,15 +11,19 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Build docker image - run: docker build . -t chat-room:latest - name: Authenticate to Docker hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PAT }} - + + - name: Build Docker image + uses: docker/build-push-action@v6 + with: + sbom: true # Enable SBOM + push: false + - name: Check for CVEs on Docker scout uses: docker/scout-action@v1 with: From 1b0ac8c36e72f359da0d596ecc54f28a7d777292 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 15 Mar 2025 00:38:43 +0300 Subject: [PATCH 52/71] Add buildx for caching --- .github/workflows/container-scan.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml index 4e486ac7a..8618efb1d 100644 --- a/.github/workflows/container-scan.yml +++ b/.github/workflows/container-scan.yml @@ -11,6 +11,8 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 + - name: Set up Buildx + uses: docker/setup-buildx-action@v3 - name: Authenticate to Docker hub uses: docker/login-action@v3 From 659bcf02b15b0722358e1aa04f019f3503da6be3 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 15 Mar 2025 00:43:11 +0300 Subject: [PATCH 53/71] Added context and Dockerfile --- .github/workflows/container-scan.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml index 8618efb1d..7d9aea0ee 100644 --- a/.github/workflows/container-scan.yml +++ b/.github/workflows/container-scan.yml @@ -23,6 +23,8 @@ jobs: - name: Build Docker image uses: docker/build-push-action@v6 with: + context: . + file: ./Dockerfile sbom: true # Enable SBOM push: false From 530a63e4231946fac26f5a43cf1a4d47ce0d8a9a Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 15 Mar 2025 00:52:08 +0300 Subject: [PATCH 54/71] Added tag --- .github/workflows/container-scan.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml index 7d9aea0ee..776537b1e 100644 --- a/.github/workflows/container-scan.yml +++ b/.github/workflows/container-scan.yml @@ -27,6 +27,7 @@ jobs: file: ./Dockerfile sbom: true # Enable SBOM push: false + tags: chat-room - name: Check for CVEs on Docker scout uses: docker/scout-action@v1 From e31231b5f9a8fc0bbd0171a5c337cabb05b54fce Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 15 Mar 2025 00:57:36 +0300 Subject: [PATCH 55/71] Made image name to be a tag --- .github/workflows/container-scan.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml index 776537b1e..44f462400 100644 --- a/.github/workflows/container-scan.yml +++ b/.github/workflows/container-scan.yml @@ -22,18 +22,20 @@ jobs: - name: Build Docker image uses: docker/build-push-action@v6 + env: + IMAGE_NAME: test/chat-room with: context: . file: ./Dockerfile sbom: true # Enable SBOM push: false - tags: chat-room + tags: ${{ env.IMAGE_NAME }} - name: Check for CVEs on Docker scout uses: docker/scout-action@v1 with: command: cves - image: chat-room:latest + image: ${{ env.IMAGE_NAME }} ignore-unchanged: true only-severities: critical,high From ab3477b9c1db0f19ab65522365e373a8cbb5b19e Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 15 Mar 2025 01:03:19 +0300 Subject: [PATCH 56/71] Remove checkout action as it is redundant. --- .github/workflows/container-scan.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml index 44f462400..eded8b037 100644 --- a/.github/workflows/container-scan.yml +++ b/.github/workflows/container-scan.yml @@ -8,8 +8,6 @@ jobs: scan-docker-image-for-vulnerabilities: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v4 - name: Set up Buildx uses: docker/setup-buildx-action@v3 From 397c2980b9f6d167edbc6ca7f2c8f2774973ec57 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 15 Mar 2025 01:09:17 +0300 Subject: [PATCH 57/71] Undo checkout repo --- .github/workflows/container-scan.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml index eded8b037..44f462400 100644 --- a/.github/workflows/container-scan.yml +++ b/.github/workflows/container-scan.yml @@ -8,6 +8,8 @@ jobs: scan-docker-image-for-vulnerabilities: runs-on: ubuntu-latest steps: + - name: Checkout repository + uses: actions/checkout@v4 - name: Set up Buildx uses: docker/setup-buildx-action@v3 From 94a56bd6225f89f7c234cebde7b60ebafe047a4a Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 15 Mar 2025 01:16:38 +0300 Subject: [PATCH 58/71] Change how image is labelled to reference Docker documentation --- .github/workflows/container-scan.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml index 44f462400..a3ced362d 100644 --- a/.github/workflows/container-scan.yml +++ b/.github/workflows/container-scan.yml @@ -4,6 +4,9 @@ on: pull_request: branches: - master + +env: + IMAGE_NAME: test/chat-room jobs: scan-docker-image-for-vulnerabilities: runs-on: ubuntu-latest @@ -20,22 +23,25 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PAT }} + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: + - name: Build Docker image uses: docker/build-push-action@v6 - env: - IMAGE_NAME: test/chat-room with: context: . file: ./Dockerfile sbom: true # Enable SBOM push: false - tags: ${{ env.IMAGE_NAME }} - + tags: ${{ steps.meta.outputs.tags }} - name: Check for CVEs on Docker scout uses: docker/scout-action@v1 with: command: cves - image: ${{ env.IMAGE_NAME }} + image: ${{ steps.meta.outputs.tags }} ignore-unchanged: true only-severities: critical,high From cb455b5fdd8bfc558c1bc7187ad6b4cbd73fd8a5 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 15 Mar 2025 01:22:56 +0300 Subject: [PATCH 59/71] Add image name --- .github/workflows/container-scan.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml index a3ced362d..967b7c825 100644 --- a/.github/workflows/container-scan.yml +++ b/.github/workflows/container-scan.yml @@ -27,7 +27,7 @@ jobs: id: meta uses: docker/metadata-action@v5 with: - images: + images: ${{ env.IMAGE_NAME }} - name: Build Docker image uses: docker/build-push-action@v6 @@ -37,6 +37,7 @@ jobs: sbom: true # Enable SBOM push: false tags: ${{ steps.meta.outputs.tags }} + - name: Check for CVEs on Docker scout uses: docker/scout-action@v1 with: From f7f0fda56ae8a2ceea298be56b1cc36ee214b6cd Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 15 Mar 2025 01:26:49 +0300 Subject: [PATCH 60/71] fix image name on CVE step --- .github/workflows/container-scan.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml index 967b7c825..84c6aa8cb 100644 --- a/.github/workflows/container-scan.yml +++ b/.github/workflows/container-scan.yml @@ -30,6 +30,7 @@ jobs: images: ${{ env.IMAGE_NAME }} - name: Build Docker image + id: build uses: docker/build-push-action@v6 with: context: . @@ -42,7 +43,7 @@ jobs: uses: docker/scout-action@v1 with: command: cves - image: ${{ steps.meta.outputs.tags }} + image: ${{ steps.id.outputs.tags }} ignore-unchanged: true only-severities: critical,high From dac8f214ceb3c33b2fc0af7913e4b056a298b77f Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 15 Mar 2025 01:36:51 +0300 Subject: [PATCH 61/71] Build docker image twice to use scout --- .github/workflows/container-scan.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml index 84c6aa8cb..5d08083d3 100644 --- a/.github/workflows/container-scan.yml +++ b/.github/workflows/container-scan.yml @@ -29,7 +29,7 @@ jobs: with: images: ${{ env.IMAGE_NAME }} - - name: Build Docker image + - name: Build Docker image to get SBOM id: build uses: docker/build-push-action@v6 with: @@ -39,11 +39,14 @@ jobs: push: false tags: ${{ steps.meta.outputs.tags }} + - name: Build image (Dirty way to do scout) + run: docker build -t chat-room . + - name: Check for CVEs on Docker scout uses: docker/scout-action@v1 with: command: cves - image: ${{ steps.id.outputs.tags }} + image: chat-room:latest ignore-unchanged: true only-severities: critical,high From 29062bc499c9d76feeeff1024a5d4119dfb1358d Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 15 Mar 2025 01:52:56 +0300 Subject: [PATCH 62/71] Made SBOM to be only production for efficiency --- .../workflows/build-and-push-to-docker-hub.yml | 1 + .github/workflows/container-scan.yml | 18 ------------------ 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/.github/workflows/build-and-push-to-docker-hub.yml b/.github/workflows/build-and-push-to-docker-hub.yml index eec5dccb9..42f040a3d 100644 --- a/.github/workflows/build-and-push-to-docker-hub.yml +++ b/.github/workflows/build-and-push-to-docker-hub.yml @@ -30,6 +30,7 @@ jobs: with: context: . file: ./Dockerfile + sbom: true # Enable SBOM push: true tags: | # Second tag makes it easy to pull the image to deployment environment ${{ secrets.DOCKER_USERNAME }}/chat-room:${{env.COMMIT_SHA}} diff --git a/.github/workflows/container-scan.yml b/.github/workflows/container-scan.yml index 5d08083d3..373075f6c 100644 --- a/.github/workflows/container-scan.yml +++ b/.github/workflows/container-scan.yml @@ -5,8 +5,6 @@ on: branches: - master -env: - IMAGE_NAME: test/chat-room jobs: scan-docker-image-for-vulnerabilities: runs-on: ubuntu-latest @@ -23,22 +21,6 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PAT }} - - name: Extract metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.IMAGE_NAME }} - - - name: Build Docker image to get SBOM - id: build - uses: docker/build-push-action@v6 - with: - context: . - file: ./Dockerfile - sbom: true # Enable SBOM - push: false - tags: ${{ steps.meta.outputs.tags }} - - name: Build image (Dirty way to do scout) run: docker build -t chat-room . From 05cad4984a0dbfe814dea2b6731ccb272848e1f7 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 23 Aug 2025 11:48:14 +0300 Subject: [PATCH 63/71] bumped asgiref from 3.4.1 to 3.6.0, django from 3.2.7 to>=4.2 ,<5.0 and djangorestframework from 3.12.4 to 3.15.2 --- requirements.txt | Bin 358 -> 364 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/requirements.txt b/requirements.txt index fc52696fd725f5afa8682e60358871362cd309d5..9cc6c02bd2c57296a01c8d85738ed332a8c3499e 100644 GIT binary patch delta 46 zcmaFH^oD7I1gjZ?9)rO|Sz~@X23rObAjgP7hrx!ybmBzOiFq-srXZ1t=cfYz@}mmZ delta 41 scmaFE^o(hO1gi;y9)saTSz}&X23rPWAjb%Z%_k=3vVs^U6R%DO0Kw=9ZU6uP From 6a95e6d029a47b5f7adf8f6a355c603df99beff0 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 23 Aug 2025 11:49:54 +0300 Subject: [PATCH 64/71] capitalized AS for conformance --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 62e038b05..1ef33795b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ # https://docs.docker.com/go/dockerfile-reference/ ARG PYTHON_VERSION=3.12 -FROM python:${PYTHON_VERSION}-slim-bookworm as base +FROM python:${PYTHON_VERSION}-slim-bookworm AS base # Prevents Python from writing pyc files. ENV PYTHONDONTWRITEBYTECODE=1 From c11ae1599f8d1cc732c4c87ff60a621bc4d4671d Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 23 Aug 2025 12:35:13 +0300 Subject: [PATCH 65/71] Added traefik labels and network --- compose.yaml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/compose.yaml b/compose.yaml index a2b39d6f5..3eeae4dfd 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,5 +1,5 @@ # Comments are provided throughout this file to help you get started. -# If you need more help, visit the Docker compose reference guide at +# If you need more help, visit the Docker Compose reference guide at # https://docs.docker.com/go/compose-spec-reference/ # Here the instructions define your application as a service called "server". @@ -8,11 +8,21 @@ # database or a cache. For examples, see the Awesome Compose repository: # https://github.com/docker/awesome-compose services: - server: + chatroom-server: build: context: . + container_name: studybud + networks: + - traefik + labels: + - "traefik.enable=true" + - "traefik.http.routers.django.rule=Host(`chatroom.kiirumaina.test`)" + - "traefik.http.services.django.loadbalancer.server.port=8000" ports: - 8000:8000 +networks: + traefik: + external: true # The commented out section below is an example of how to define a PostgreSQL # database that your application can use. `depends_on` tells Docker Compose to From e3b4c162fa75c05c2088fe5969f743f7c39a6c8b Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sat, 23 Aug 2025 12:35:35 +0300 Subject: [PATCH 66/71] updated .dockerignore --- .dockerignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index 5b3d79a85..03a268b8b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -23,7 +23,7 @@ **/bin **/charts **/docker-compose* -**/compose* +**/compose.y*ml **/Dockerfile* **/node_modules **/npm-debug.log From 4a3f98de46a9fa2ef2e8cad201f83fb2e1be7102 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sun, 24 Aug 2025 13:34:09 +0300 Subject: [PATCH 67/71] Remove duplicate port entry and added entrypoint --- compose.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compose.yaml b/compose.yaml index 3eeae4dfd..ab3f5b6c4 100644 --- a/compose.yaml +++ b/compose.yaml @@ -18,8 +18,7 @@ services: - "traefik.enable=true" - "traefik.http.routers.django.rule=Host(`chatroom.kiirumaina.test`)" - "traefik.http.services.django.loadbalancer.server.port=8000" - ports: - - 8000:8000 + - "traefik.http.routers.django.entrypoints=web" networks: traefik: external: true From aa14d3f1258e907b093a75a4173fe2dc769a52ef Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sun, 24 Aug 2025 13:34:32 +0300 Subject: [PATCH 68/71] Added test domain for local environment --- studybud/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/studybud/settings.py b/studybud/settings.py index 6f29daf45..3d60ef7db 100644 --- a/studybud/settings.py +++ b/studybud/settings.py @@ -25,7 +25,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = ["0.0.0.0", "127.0.0.1", "chatroom.kiirumaina.com"] +ALLOWED_HOSTS = ["0.0.0.0", "127.0.0.1", "chatroom.kiirumaina.com", "chatroom.kiirumaina.test"] # Application definition From cc5cd0135cd83feb668f86bd02542930162b4726 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Sun, 24 Aug 2025 13:42:43 +0300 Subject: [PATCH 69/71] Added running with Docker. --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b1f339483..b749e0324 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,18 @@ pip install -r requirements.txt ``` -# +### Running the App on Docker +--> Run the application using the following command: +```bash +docker compose up -d --build + +``` +Navigate to the application on `localhost:8000` + +If you have traefik ensure that traefik is running first then visit http://chatroom.kiirumaina.test + -### Running the App +### Running the App on PC --> To run the App, we use : ```bash From 55b1f09ced7da37be8ee5ccb8fc3f7f514a25479 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Wed, 27 Aug 2025 21:30:02 +0300 Subject: [PATCH 70/71] Enforce https on docker container --- compose.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/compose.yaml b/compose.yaml index ab3f5b6c4..0d9e14af1 100644 --- a/compose.yaml +++ b/compose.yaml @@ -8,17 +8,18 @@ # database or a cache. For examples, see the Awesome Compose repository: # https://github.com/docker/awesome-compose services: - chatroom-server: + chat-room: build: context: . - container_name: studybud + container_name: chat-room + restart: unless-stopped networks: - traefik labels: - "traefik.enable=true" - - "traefik.http.routers.django.rule=Host(`chatroom.kiirumaina.test`)" + - "traefik.http.routers.django.rule=Host(`chatroom.docker.localhost`)" - "traefik.http.services.django.loadbalancer.server.port=8000" - - "traefik.http.routers.django.entrypoints=web" + - "traefik.http.routers.django.entrypoints=websecure" networks: traefik: external: true From da830a8f876e537d62f991e0e33fa29b1043b068 Mon Sep 17 00:00:00 2001 From: kiiru4reals Date: Wed, 27 Aug 2025 21:30:40 +0300 Subject: [PATCH 71/71] updated domain name for local environment --- README.md | 2 +- studybud/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b749e0324..b6bad5054 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ docker compose up -d --build ``` Navigate to the application on `localhost:8000` -If you have traefik ensure that traefik is running first then visit http://chatroom.kiirumaina.test +If you have traefik ensure that traefik is running first then visit https://chatroom.docker.localhost ### Running the App on PC diff --git a/studybud/settings.py b/studybud/settings.py index 3d60ef7db..bf17b48ec 100644 --- a/studybud/settings.py +++ b/studybud/settings.py @@ -25,7 +25,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = ["0.0.0.0", "127.0.0.1", "chatroom.kiirumaina.com", "chatroom.kiirumaina.test"] +ALLOWED_HOSTS = ["0.0.0.0", "127.0.0.1", "chatroom.kiirumaina.com", "chatroom.docker.localhost"] # Application definition