Skip to content

Commit

Permalink
infra: Add Makefile to build the website
Browse files Browse the repository at this point in the history
The most important rules defined in this Makefile are:
- `make`: build the website locally in the `.output` directory
- `make serve`: to open a `python3` server which allows you to view the
content at `http://localhost:8080/operating-systems`
- `make cleanall`: stop the server and remove the container and all
docker images

Signed-off-by: Teodor Dutu <[email protected]>
  • Loading branch information
teodutu committed Nov 28, 2023
1 parent 38c0415 commit 4303f8a
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
REPO_NAME = operating-systems
IMAGE_NAME = $(REPO_NAME)/docusaurus:latest
CONTAINER_NAME = open-edu-hub-$(REPO_NAME)-bash
OUTPUT_DIR = $$PWD/.output/$(REPO_NAME)

.PHONY: all buildimg build serve run_bash enter_bash stop_bash clean cleanall

all: build

buildimg:
docker build -f ./Dockerfile --tag $(IMAGE_NAME) .

build: buildimg
@echo "Building content. This will take a while (several minutes) ..."
@echo "After the build, run"
@echo ""
@echo " make serve"
@echo ""
@mkdir -p $(OUTPUT_DIR)
docker run --rm -v $$PWD/:/content -v $(OUTPUT_DIR):/output $(IMAGE_NAME)

serve:
@echo "Point your browser to http://localhost:8080/$(REPO_NAME)"
@cd $(OUTPUT_DIR)/.. && python3 -m http.server 8080

run_bash: buildimg
@mkdir -p $(OUTPUT_DIR)
docker run -d -it --entrypoint /bin/bash --name $(CONTAINER_NAME) -v $$PWD/:/content -v $(OUTPUT_DIR):/output $(IMAGE_NAME)

enter_bash:
docker exec -it $(CONTAINER_NAME) /bin/bash

stop_bash:
-test "$(shell docker container inspect -f '{{.State.Running}}' $(CONTAINER_NAME) 2> /dev/null)" = "true" && docker stop $(CONTAINER_NAME)

clean: stop_bash
-docker container inspect $(CONTAINER_NAME) > /dev/null 2>&1 && docker rm $(CONTAINER_NAME)
-sudo rm -fr $(OUTPUT_DIR)

cleanall: clean
-docker inspect --type=image $(IMAGE_NAME) > /dev/null 2>&1 && docker image rm $(IMAGE_NAME)

0 comments on commit 4303f8a

Please sign in to comment.