Skip to content

Commit

Permalink
commands: improve local development commands (bug 1917079) (#124)
Browse files Browse the repository at this point in the history
- run migrations
- ensure local repos exists
- ensure local workers exists
- ensure admin user exists
- update README
- update Makefile
  • Loading branch information
zzzeid authored Sep 6, 2024
1 parent d384491 commit c438818
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 25 deletions.
30 changes: 12 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ SHELL := /bin/bash
DOCKER := $(shell which docker)
DOCKER_COMPOSE := $(shell which docker-compose)

ifeq ($(STANDALONE), 1)
BASE_COMMAND := docker-compose run lando
else
BASE_COMMAND := docker exec -ti suite-lando-1
endif

.PHONY: help
help:
Expand All @@ -11,38 +16,27 @@ help:
@echo
@echo "target is one of:"
@echo " help show this message and exit"
@echo " build build the docker image for lando"
@echo " format run ruff and black on source code"
@echo " test run the test suite"
@echo " migrations generates migration files to reflect model changes in the database"
@echo " start run the application"
@echo " stop stop the application"
@echo " attach attach for debugging (ctrl-p ctrl-q to detach)"

.PHONY: test
test:
docker-compose run lando lando tests
$(BASE_COMMAND) lando tests

.PHONY: format
format:
docker-compose run lando lando format

.PHONY: build
build:
docker-compose build
$(BASE_COMMAND) lando format

.PHONY: migrations
migrations:
docker-compose run lando lando makemigrations

.PHONY: start
start:
docker-compose up -d

.PHONY: stop
stop:
docker-compose down
$(BASE_COMMAND) lando makemigrations

.PHONY: attach
attach:
ifeq ($(INSUITE), 1)
-@docker attach suite-lando-1 ||:
else
-@docker-compose attach lando ||:
endif
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ Lando is an application that applies patches and pushes them to Git and Mercuria
* docker compose

### Running the development server
It is recommended to use "conduit suite" to interact with Lando on your local machine, however, it can also be run using docker-compose if needed.

make start
docker-compose up

The above command will run any database migrations and start the development server and its dependencies.

make stop
docker-compose down

The above command will shut down the containers running lando.

## Specifying Suite or Stand-alone
By default, make commands will assume you are running them in suite. This will run the commands in the lando container in the suite. If you want to explicitly run commands on a standalone Lando container (i.e., if you started the container via `docker-compose up` above), then set STANDALONE=1. For example:

STANDALONE=1 make test

## Testing

To run the test suite, invoke the following command:
Expand Down
1 change: 0 additions & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3.8"
services:
db:
image: postgres
Expand Down
10 changes: 7 additions & 3 deletions src/lando/utils/management/commands/create_environment_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,12 @@ def handle(self, *args, **options):
try:
repo = Repo.objects.create(**definition)
except IntegrityError:
self.stderr.write(
f"Repo {definition['name']} already exists, skipping."
self.stdout.write(
self.style.WARNING(
f"Repo {definition['name']} already exists, skipping."
)
)
else:
self.stdout.write(f"Created repo {repo.tree} ({repo.id}).")
self.stdout.write(
self.style.SUCCESS(f"Created repo {repo.tree} ({repo.id}).")
)
19 changes: 18 additions & 1 deletion src/lando/utils/management/commands/setup_dev.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.conf import settings
from django.contrib.auth.models import User
from django.core.management import call_command
from django.core.management.base import BaseCommand, CommandError

from lando.environments import Environment
Expand Down Expand Up @@ -33,6 +34,12 @@ def setup_workers(self):
# Associate all repos with applicable worker.
self.stdout.write(f"Adding {repo} ({repo.scm}) to {workers[repo.scm]}.")
workers[repo.scm].applicable_repos.add(repo)
self.stdout.write(
self.style.SUCCESS(
'Workers initialized ("hg" and "git"). '
"To start one, run `lando start_landing_worker <name>`.",
)
)

def setup_users(self):
"""Ensure there is an administrator account on the local system."""
Expand All @@ -51,10 +58,20 @@ def setup_users(self):
user.is_superuser = True
user.is_staff = True
user.save()
self.stdout.write(
self.style.SUCCESS(
"Superuser created with the following username and password: "
'"admin", "password".'
)
)

def handle(self, *args, **options):
if settings.ENVIRONMENT != Environment.local:
raise CommandError("This script can only be run on a local environment.")
call_command("migrate")
call_command("create_environment_repos", Environment.local.value)
self.setup_workers()
self.setup_users()
self.stdout.write("Finished.")
self.stdout.write(
self.style.SUCCESS("Finished setting up local Lando environment.")
)

0 comments on commit c438818

Please sign in to comment.