Skip to content

Commit

Permalink
TR-785 Create action that builds the Honeyquest container
Browse files Browse the repository at this point in the history
  • Loading branch information
blu3r4y committed Jul 29, 2024
1 parent 51b84d0 commit 0ba717e
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 6 deletions.
125 changes: 125 additions & 0 deletions .github/workflows/build-honeyquest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: build-honeyquest

on:
pull_request:
push:
branches:
- main
tags:
- v*

env:
IMAGE_NAME: ghcr.io/dynatrace-oss/honeyquest

jobs:
pre-commit-hooks:
runs-on: ubuntu-latest
container:
image: nikolaik/python-nodejs:python3.10-nodejs20@sha256:97f8a87d28786db28a2796ca3932a52aaff75b703f9020a29fd6fc4387f64b47
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Fix git permissions
run: git config --global --add safe.directory $PWD

- name: Fix cache directory permissions
run: |
mkdir -p ~/.npm
mkdir -p ~/.cache/pypoetry
mkdir -p ~/.cache/pre-commit
chown -R $USER:$USER ~/.npm
chown -R $USER:$USER ~/.cache/pypoetry
chown -R $USER:$USER ~/.cache/pre-commit
- name: Cache Poetry packages
id: cache-poetry
uses: actions/cache@v4
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
- name: Cache npm packages
id: cache-npm
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Cache pre-commit environments
id: cache-pre-commit
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: ${{ runner.os }}-pre-commit-${{ hashFiles('**/.pre-commit-config.yaml') }}
restore-keys: |
${{ runner.os }}-pre-commit-
- name: Install pre-commit hooks
run: python -m pip install --upgrade pre-commit

- name: Install Node dependencies
working-directory: ./src/honeyfront
run: npm install

- name: Install Python dependencies
working-directory: ./src/honeyback
run: poetry install --with hooks,analytics
env:
RPY2_CFFI_MODE: ABI # needed for rpy2

- name: Activate Poetry environment
working-directory: ./src/honeyback
shell: bash
run: |
source $(poetry env info --path)/bin/activate
echo "$VIRTUAL_ENV/bin" >> $GITHUB_PATH
echo "PYTHONHOME=" >> $GITHUB_ENV
- name: Run pre-commit hooks
run: pre-commit run -v --all-files --show-diff-on-failure

build-honeyquest:
needs: pre-commit-hooks
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.IMAGE_NAME }}
tags: |
type=sha
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GHCR
uses: docker/login-action@v3
if: ${{ github.event_name == 'push' }}
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push images
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name == 'push' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
cache-to: ${{ github.event_name == 'push' && format('type=registry,ref={0}:buildcache,mode=max', env.IMAGE_NAME) || '' }}
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ repos:
- id: isort
name: sort imports with isort
args: ["--settings-path", "./src/honeyback/pyproject.toml"]
files: \.py$
files: ^src\/honeyback\/.*\.py$
- repo: https://github.com/ambv/black
rev: 24.4.2
hooks:
- id: black
name: format files with black
args: ["--config", "./src/honeyback/pyproject.toml"]
files: \.py$
files: ^src\/honeyback\/.*\.py$
language_version: python3
- repo: https://github.com/PyCQA/flake8
rev: 7.1.0
hooks:
- id: flake8
name: lint files with flake8
args: ["--config", "./src/honeyback/tox.ini"]
files: \.py$
files: ^src\/honeyback\/.*\.py$
additional_dependencies:
- flake8-docstrings
- flake8-rst-docstrings
Expand All @@ -98,14 +98,14 @@ repos:
name: lint files with pylint
entry: poetry run -C ./src/honeyback pylint --rcfile ./src/honeyback/pyproject.toml -sn -rn
language: system
files: \.py$
files: ^src\/honeyback\/.*\.py$
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.0
hooks:
- id: mypy
name: check types with mypy
args: ["--config-file", "./src/honeyback/pyproject.toml"]
files: \.py$
files: ^src\/honeyback\/.*\.py$
additional_dependencies:
# packages with built-in type stubs
- numpy>=1.26.4,<2.0
Expand Down
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
"**/.mypy_cache": true,
"**/.pytest_cache": true
},
"flake8.args": ["--config=${workspaceFolder}/src/honeyback/tox.ini"]
"flake8.args": [
"--config=${workspaceFolder}/src/honeyback/tox.ini"
],
"[github-actions-workflow]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}

0 comments on commit 0ba717e

Please sign in to comment.