Skip to content

Commit

Permalink
makefile checks for correct docker compose command
Browse files Browse the repository at this point in the history
  • Loading branch information
glass-ships committed Aug 6, 2024
1 parent 9d23c49 commit 9bc990e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 16 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Set update schedule for GitHub Actions

version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"
37 changes: 31 additions & 6 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
name: unit-test
name: Run unit tests

on:
workflow_dispatch:
pull_request:
push:
branches: [next, qa, main]
tags: ['v*']
tags: ["v*"]

jobs:
linux:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}

env:
DATABASE_NAME: livedatadb
DATABASE_USER: livedatauser
Expand All @@ -23,29 +24,51 @@ jobs:
DJANGO_SUPERUSER_USERNAME: livedatauser
DJANGO_SUPERUSER_PASSWORD: livedatapass
COVERAGE_RUN: coverage run -m

steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
- name: Checkout code
uses: actions/checkout@v4

- name: Cache conda
uses: actions/cache@v4
env:
# Increase this value to reset cache if etc/example-environment.yml has not changed
CACHE_NUMBER: 0
with:
path: ~/conda_pkgs_dir
key: ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('etc/example-environment.yml') }}

- name: Setup Conda environment
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
channels: conda-forge,defaults
mamba-version: "*"
environment-file: environment.yml
cache-environment-key: ${{ runner.os }}-env-${{ hashFiles('**/environment.yml') }}
cache-downloads-key: ${{ runner.os }}-downloads-${{ hashFiles('**/environment.yml') }}
use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly!
# These don't seem to be valid options for this action
# See: https://github.com/conda-incubator/setup-miniconda
# cache-environment-key: ${{ runner.os }}-env-${{ hashFiles('**/environment.yml') }}
# cache-downloads-key: ${{ runner.os }}-downloads-${{ hashFiles('**/environment.yml') }}

- name: Start docker containers
run: |
cp ./config/docker-compose.envlocal.yml docker-compose.yml
docker-compose up --build -d
- name: Sleep, wait for containers to start up
run: sleep 30

- name: Run unit tests
run: python -m pytest tests/

- name: Stop the coverage process
# Stopping the coverage process allows the code coverage to be written to disk
run: docker exec live_data_server_livedata_1 /bin/bash -c "pkill coverage"

- name: Copy code coverage out of docker container
run: docker cp live_data_server_livedata_1:/var/www/livedata/app /tmp/

- name: Combine and show code coverage
shell: bash -l {0}
run: |
Expand All @@ -54,9 +77,11 @@ jobs:
coverage xml
cp coverage.xml $OLDPWD
coverage report
- name: Bring down docker containers completely now
# This will completely remove the containers
run: docker-compose down

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.1
rev: v0.5.6
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
16 changes: 9 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ app_dir := live_data_server
DJANGO_COMPATIBLE:=$(shell python -c "import django;t=0 if django.VERSION[0]<4 else 1; print(t)")
DJANGO_VERSION:=$(shell python -c "import django;print(django.__version__)")

# command to run docker compose. change this to be what you have installed
# this can be overriden on the command line
# DOCKER_COMPOSE="docker compose" make docker/pruneall
DOCKER_COMPOSE ?= docker-compose
ifneq ($(shell docker compose version 2>/dev/null),)
DOCKER_COMPOSE=docker compose
else ifneq ($(shell docker-compose --version 2>/dev/null),)
DOCKER_COMPOSE=docker-compose
endif


help:
# this nifty perl one-liner collects all comments headed by the double "#" symbols next to each target and recycles them as comments
Expand All @@ -30,10 +32,10 @@ docker/pruneall: docker/compose/validate ## stop all containers, then remove al
docker/compose/validate: ## validate the version of the docker-compose command. Exits quietly if valid.
@./scripts/docker-compose_validate.sh $(DOCKER_COMPOSE)

local/docker/up: docker/compose/validate ## compose and start the service locally
docker/compose/local: docker/compose/validate ## compose and start the service locally
\cp ./config/docker-compose.envlocal.yml docker-compose.yml
$(DOCKER_COMPOSE) up --build

.PHONY: check
.PHONY: first_install
.PHONY: help
Expand All @@ -42,4 +44,4 @@ local/docker/up: docker/compose/validate ## compose and start the service locall
.PHONY: webapp/core
.PHONY: docker/compose/validate
.PHONY: docker/pruneall
.PHONY: local/docker/up
.PHONY: docker/compose/local
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export DJANGO_SUPERUSER_PASSWORD=$DATABASE_PASS
After the secrets are set, type in the terminal shell:

```bash
make local/docker/up
make docker/compose/local
```

This command will copy `config/docker-compose.envlocal.yml` into `docker-compose.yml` before composing all the services.
Expand Down
2 changes: 1 addition & 1 deletion docs/developer/config_for_local_use.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ After the secrets are set, you can start the server with:

.. code-block:: bash
make local/docker/up
make docker/compose/local
This command will copy ``config/docker-compose.envlocal.yml`` into ``./docker-compose.yml`` before composing all the services.

Expand Down

0 comments on commit 9bc990e

Please sign in to comment.