Skip to content

Commit

Permalink
TMP: stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed May 10, 2024
1 parent 5c1e4a0 commit 610fa58
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
7 changes: 5 additions & 2 deletions Makefile-docker
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ initialize_db: ## create a new database
$(PYTHON_COMMAND) manage.py migrate --noinput
$(PYTHON_COMMAND) manage.py loaddata initial.json
$(PYTHON_COMMAND) manage.py import_prod_versions
$(PYTHON_COMMAND) manage.py createsuperuser
$(PYTHON_COMMAND) manage.py createsuperuser \
--no-input \
--username "$(SUPERUSER_USERNAME)" \
--email $(SUPERUSER_EMAIL)
$(PYTHON_COMMAND) manage.py loaddata zadmin/users

.PHONY: populate_data
Expand Down Expand Up @@ -225,7 +228,7 @@ dbshell: ## connect to a database shell
$(PYTHON_COMMAND) ./manage.py dbshell

.PHONY: initialize
initialize: update_deps initialize_db update_assets populate_data ## init the dependencies, the database, and assets
initialize: initialize_db populate_data ## init the dependencies, the database, and assets

.PHONY: reload
reload: ## force django code reload
Expand Down
54 changes: 47 additions & 7 deletions Makefile-os
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
export HOST_UID := $(shell id -u)
####################################################################################################

# First, set the critical environment variables, using the priority
export DOCKER_BUILDER=container
# make arguments ex: make <command> HOST_UID=1000

# .env if the file exists
DOCKER_TAG := addons-server-test
# default values if not defined
DOCKER_PLATFORM := linux/amd64
# These variables are saved to the .env file so that running docker compose
DOCKER_PROGRESS := auto
# produces the same results as running make commands
export DOCKER_COMMIT := $(shell git rev-parse HEAD || echo "commit")
# Include existing .env values if they exist
DOCKER_CACHE_DIR := docker-cache
-include $(wildcard .env)


export DOCKER_VERSION ?= local
# If the .env variables are not set, use the defaults
export VERSION_BUILD_URL ?= build
# The HOST_UID is used for mapping the host user id to the olympia user inside a running container
HOST_UID ?= $(shell id -u)
# The COMPOSE_FILE is used to specify which configuration `docker compose` should use
# this applies both to make command and raw docker compose commands via the .env file
# IMPORTANT: COMPOSE_FILE is ignored by `docker buildx build` so make build_docker_image
# explicitly specifies the files to use
COMPOSE_FILE ?= docker-compose.yml
# define the username and email for the superuser in the container
SUPERUSER_EMAIL=$(shell git config user.email)
SUPERUSER_USERNAME=$(shell git config user.name)
# define the version and target of the container
DOCKER_VERSION ?= local
DOCKER_TARGET ?= development
####################################################################################################

DOCKER_BUILDER=container
DOCKER_PROGRESS ?= auto
DOCKER_PUSH ?= false
DOCKER_COMMIT ?= $(shell git rev-parse HEAD || echo "commit")
VERSION_BUILD_URL ?= build
# Exporting these variables make them default values for docker-compose*.yml files
export DOCKER_VERSION ?= local
export DOCKER_TARGET ?= development

.PHONY: help_redirect
help_redirect:
Expand Down Expand Up @@ -42,7 +73,13 @@ rootshell: ## connect to a running addons-server docker shell with root user

.PHONY: create_env_file
create_env_file:
echo "HOST_UID=${HOST_UID}" > .env
@ rm -f .env
echo "HOST_UID=${HOST_UID}" >> .env
echo "COMPOSE_FILE=${COMPOSE_FILE}" >> .env
echo "SUPERUSER_EMAIL=${SUPERUSER_EMAIL}" >> .env
echo "SUPERUSER_USERNAME=${SUPERUSER_USERNAME}" >> .env
echo "DOCKER_VERSION=${DOCKER_VERSION}" >> .env
echo "DOCKER_TARGET=${DOCKER_TARGET}" >> .env

.PHONY: create_docker_builder
create_docker_builder: ## Create a custom builder for buildkit to efficiently build local images
Expand All @@ -51,6 +88,7 @@ create_docker_builder: ## Create a custom builder for buildkit to efficiently bu
--driver=docker-container

DOCKER_BUILD_ARGS := \
--file=docker-compose.yml \
--progress=$(DOCKER_PROGRESS) \
--builder=$(DOCKER_BUILDER) \

Expand All @@ -73,8 +111,7 @@ docker_compose_config: ## Show the docker compose configuration
echo $(DOCKER_BUILD_ARGS)

.PHONY: build_docker_image
build_docker_image: create_docker_builder version docker_compose_config ## Build the docker image
docker buildx bake web $(DOCKER_BUILD_ARGS) --print
build_docker_image: create_docker_builder version ## Build the docker image
docker buildx bake web $(DOCKER_BUILD_ARGS)

.PHONY: docker_compose_down
Expand Down Expand Up @@ -103,6 +140,9 @@ docker_extract_deps: ## Extract dependencies from the docker image to a local vo
.PHONY: up
up: create_env_file build_docker_image docker_extract_deps docker_compose_up ## Create and start docker compose

.PHONY: down
down: docker_compose_down ## Stop the docker containers

.PHONY: initialize_docker
initialize_docker: up
docker compose exec --user olympia web make initialize
Expand Down
3 changes: 3 additions & 0 deletions docker-compose._base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ x-env-mapping: &env
- HISTSIZE=50000
- HISTIGNORE=ls:exit:"cd .."
- HISTCONTROL=erasedups
# This is the email address of the superuser created when initializing the db
- SUPERUSER_EMAIL=${SUPERUSER_EMAIL:-admin@mozilla.com}
- SUPERUSER_USERNAME=${SUPERUSER_USERNAME:-admin}

services:
worker: &worker
Expand Down
1 change: 0 additions & 1 deletion docker-compose._mount_olympia.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ services:
- HOST_UID=${HOST_UID:-}
volumes:
- .:/data/olympia
- /data/olympia/src/olympia.egg-info
web:
extends:
service: worker

0 comments on commit 610fa58

Please sign in to comment.