Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use service profiles to specify drunc-lite use case #147

Merged
merged 8 commits into from
Oct 17, 2024

Conversation

TinyMarsh
Copy link
Contributor

@TinyMarsh TinyMarsh commented Oct 10, 2024

Description

Uses profiles in Compose to allow the user to selectively activate either the full drunc service, or the dunc-lite service.

To test run either;

docker compose --profile drunc up

or

docker compose --profile drunc-lite up

for the full or lite services, respectively.

Fixes #115

Type of change

  • Documentation (non-breaking change that adds or improves the documentation)
  • New feature (non-breaking change which adds functionality)
  • Optimization (non-breaking, back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (whatever its nature)

Key checklist

  • All tests pass (eg. python -m pytest)
  • The documentation builds and looks OK (eg. python -m sphinx -b html docs docs/build)
  • Pre-commit hooks run successfully (eg. pre-commit run --all-files)

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added or an issue has been opened to tackle that in the future. (Indicate issue here: # (issue))

@TinyMarsh TinyMarsh marked this pull request as ready for review October 14, 2024 10:31
Copy link
Contributor

@cc-a cc-a left a comment

Choose a reason for hiding this comment

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

Looks promising but its based on a fairly old version of main at this point and a couple of other services have been added to docker-compose.yml. Could you update?

Copy link
Contributor

@alexdewar alexdewar left a comment

Choose a reason for hiding this comment

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

LGTM except for the pre-commit thing!

I'm guessing the lite image is exactly the same as we had before...?

.github/workflows/pre-commit.yml Outdated Show resolved Hide resolved
docker-compose.yml Outdated Show resolved Hide resolved
Copy link
Contributor

@jamesturner246 jamesturner246 left a comment

Choose a reason for hiding this comment

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

Looks good, besides the sh -> bash thing. 👍 One question.

Comment on lines +32 to +33
profiles:
- drunc-lite
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean that --profile is now required, or does it somehow default to one or the other?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The former. It's necessary for both drunc and drunc-lite services. I couldn't find an elegant way to default to one or the other in the absence of --profile.

@TinyMarsh
Copy link
Contributor Author

TinyMarsh commented Oct 16, 2024

Some thoughts on continuing the work in this PR...

After bringing this branch up to date with main, I noticed that we would need to find a way to dynamically pass the correct value to the PROCESS_MANAGER_URL environment variable;

- PROCESS_MANAGER_URL=drunc:10054

I was considering handling this with a bash script, where the user can pass by argument which drunc service to run and, at the same time, set the PROCESS_MANAGER_URL by setting a Bash environment variable (DRUNC_SERVICE). For example:

#scripts/run_docker_compose.sh
#!/bin/bash

PROFILE=$1

# Set environment variable based on the profile
if [ "$PROFILE" == "drunc-lite" ]; then
  export DRUNC_SERVICE=drunc-lite
else
  export DRUNC_SERVICE=drunc
fi

# Run Docker Compose with the specified profile
docker compose --profile $PROFILE up

Then, in docker-compose.yml:

services:
  app:
    build: .
    command:
      - bash
      - -c
      - |
        python manage.py migrate
        python manage.py runserver 0:8000
    ports:
      - 127.0.0.1:8000:8000
    volumes:
      - .:/usr/src/app
      - db:/usr/src/app/db
    environment:
      - PROCESS_MANAGER_URL=${DRUNC_SERVICE}:10054
    depends_on:
      - ${DRUNC_SERVICE}

# ... (rest of docker-compose.yml)

It feels a bit hacky, but from the user's perspective it's still just running one line, e.g. ./scripts/run_docker_compose.sh drunc-lite. Unfortunately, whilst implementing this, the app seems to have stopped working on my system (even when I have main checked out 😞) and I ran out of time whilst debugging that.

@cc-a cc-a merged commit 4adb194 into full-drunc-image Oct 17, 2024
4 checks passed
@cc-a cc-a deleted the drunc-image-profiles branch October 17, 2024 14:18
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.55%. Comparing base (870aa9c) to head (6bfd64f).
Report is 9 commits behind head on full-drunc-image.

Additional details and impacted files
@@                Coverage Diff                @@
##           full-drunc-image     #147   +/-   ##
=================================================
  Coverage             80.55%   80.55%           
=================================================
  Files                    26       26           
  Lines                   324      324           
=================================================
  Hits                    261      261           
  Misses                   63       63           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants