Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ravescovi committed Mar 1, 2024
2 parents 20a4a25 + b6c0532 commit a2a3458
Show file tree
Hide file tree
Showing 35 changed files with 1,118 additions and 1,685 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Docker Build Only

# 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.

on:
push:
branches: [ "!main" ]
pull_request:
branches: [ "*" ]


env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}


jobs:
docker_build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=raw,value=latest,enable={{is_default_branch}}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build Docker image
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
#cache-from: type=gha
#cache-to: type=gha,mode=max
74 changes: 74 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Docker Build and Publish

# 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.

on:
push:
branches: [ "main" ]
# Publish semver tags as releases.
tags: [ '*' ]

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}


jobs:
build_and_publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=raw,value=latest,enable={{is_default_branch}}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
#cache-from: type=gha
#cache-to: type=gha,mode=max
15 changes: 15 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Pre-Commit Checks

on:
push:

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: Checkout code
- uses: actions/setup-python@v3
name: Setup Python
- uses: pre-commit/[email protected]
name: Run Pre-Commit Checks
19 changes: 19 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Pytest Unit Tests

on: [push]

jobs:
build_and_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: Checkout code
- name: Test makefile
run: make init .env
- name: Check .env file
run: cat .env
- name: Create paths
run: make paths
- name: Initialize, Build, and Test with Docker
run: make test
shell: bash
49 changes: 36 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#package specific ignores
*_logs/*.log
*.log

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand All @@ -24,7 +20,6 @@ parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
Expand Down Expand Up @@ -54,6 +49,7 @@ coverage.xml
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
Expand All @@ -76,6 +72,7 @@ instance/
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
Expand All @@ -86,7 +83,9 @@ profile_default/
ipython_config.py

# pyenv
.python-version
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
Expand All @@ -95,7 +94,22 @@ ipython_config.py
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
Expand Down Expand Up @@ -131,10 +145,19 @@ dmypy.json

# Pyre type checker
.pyre/
.vscode/

# OS generated files #
######################
.DS_Store
.DS_Store?
._*
# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# WEI
.wei
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
- id: check-json
- id: check-toml
- id: check-ast
- id: check-merge-conflict
- id: check-added-large-files
- id: mixed-line-ending
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/kynan/nbstripout
rev: 0.6.1
hooks:
- id: nbstripout
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.10
hooks:
# Run the linter.
- id: ruff
args: [--fix]
# Run the formatter.
- id: ruff-format
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ enforcement ladder](https://github.com/mozilla/diversity).

For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
https://www.contributor-covenant.org/translations.
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ RUN --mount=type=cache,target=/root/.cache \
pip install -e ./hudson_platecrane_module

CMD ["python", "hudson_platecrane_module/src/sciclops_rest_node.py"]
<<<<<<< HEAD
=======

# Add user to video group to access hudson_platecrane
RUN usermod -a -G video app

>>>>>>> b6c05324ef588685558bdbf33fcfa974c3672eae
#########################################
48 changes: 30 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
.DEFAULT_GOAL := all
isort = python -m isort .
black = python -m black --target-version py39 .
# Python Configuration
PYPROJECT_TOML := pyproject.toml
PROJECT_VERSION := $(shell grep -oP '(?<=version = ")[^"]+' $(PYPROJECT_TOML) | head -n 1)

.PHONY: format
format:
$(isort)
$(black)
.DEFAULT_GOAL := init

.PHONY: lint
lint:
$(black) --check --diff
python -m flake8 .
python -m pydocstyle . --count
.PHONY += init paths checks test clean
init: # Do the initial configuration of the project
@test -e .env || cp example.env .env
@sed -i 's/^USER_ID=.*/USER_ID=$(shell id -u)/' .env
@sed -i 's/^GROUP_ID=.*/GROUP_ID=$(shell id -g)/' .env
@sed -i 's/^PROJECT_VERSION=.*/PROJECT_VERSION=$(PROJECT_VERSION)/' .env
@sed -i 's/^PROJECT_PATH=.*/PROJECT_PATH=$(shell pwd | sed 's/\//\\\//g')/' .env

.env: init

paths: .env # Create the necessary data directories
@mkdir -p $(shell grep -E '^WEI_DATA_DIR=' .env | cut -d '=' -f 2)
@mkdir -p $(shell grep -E '^REDIS_DIR=' .env | cut -d '=' -f 2)

.PHONY: mypy
mypy:
mypy --config-file setup.cfg --package .
mypy --config-file setup.cfg .
checks: # Runs all the pre-commit checks
@pre-commit install
@pre-commit run --all-files || { echo "Checking fixes\n" ; pre-commit run --all-files; }

.PHONY: all
all: format lint
test: init .env paths # Runs all the tests
@docker compose -f wei.compose.yaml --env-file .env up --build -d
@docker compose -f wei.compose.yaml --env-file .env exec sciclops pytest -p no:cacheprovider -m "not hardware" hudson_platecrane_module
@docker compose -f wei.compose.yaml --env-file .env down

hardware_test: init .env paths # Runs all the tests
@docker compose -f wei.compose.yaml --env-file .env up --build -d
@docker compose -f wei.compose.yaml --env-file .env exec sciclops pytest -p no:cacheprovider -m "hardware" hudson_platecrane_module
@docker compose -f wei.compose.yaml --env-file .env down

clean:
@rm .env
Loading

0 comments on commit a2a3458

Please sign in to comment.