From df92de60da2b2e8fff9ba063e08adad85392e2f6 Mon Sep 17 00:00:00 2001 From: Sangelo Date: Tue, 2 Apr 2024 17:42:33 +0200 Subject: [PATCH] [a] Initial Justfile build script --- Justfile | 84 ++++++++++++++++++++++++++++++++++++++++ README.md | 36 ++++++++++++++++- docker-compose.build.yml | 3 +- 3 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 Justfile diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..4334a5f --- /dev/null +++ b/Justfile @@ -0,0 +1,84 @@ +# settings +set dotenv-load + +# defaults +default_runner := 'docker' +default_tag := 'latest' +default_image := 'gitpot.dev/sangelo/website:latest' + +# run development server by default +default: dev + +# aliases +alias c := clean +alias b := build +alias r := run +alias d := dev +alias p := preview + +# building + +# run all docker related recipes (clean, build, run) (default runner: docker) +all tag=default_tag runner=default_runner: + just -f {{justfile()}} clean {{runner}} {{tag}} + just -f {{justfile()}} build {{tag}} {{runner}} + just -f {{justfile()}} run {{tag}} {{runner}} + +# clean containers, images and temporary svelte dirs with specified runner (default runner: docker) +clean runner=default_runner tag=default_tag: + @echo "Cleaning dev environment..." + rm -rf build/ .svelte-kit/ + @echo "Cleaning containers with '{{runner}}'..." + TAG="{{tag}}" {{runner}} compose -f docker-compose.build.yml down + @echo "Cleaning images with '{{runner}}'..." + just -f {{justfile()}} _clean_images {{runner}} + +# clean images function +_clean_images runner=default_runner: + #!/usr/bin/env bash + set -euo pipefail + image_ids=$({{runner}} image ls | grep gitpot.dev/sangelo/website | awk '{print $3}') + if [ -n "$image_ids" ]; then + for image_id in $image_ids; do + {{runner}} image rm $image_id + echo "Image with ID $image_id deleted successfully." + done + else + echo "No images matching the repository and tag found." + fi + +# build container image with specified runner (default runner: docker) +build tag=default_tag runner=default_runner: + @echo "Running with '{{runner}}' and tagging as '{{tag}}'..." + TAG="{{tag}}" {{runner}} compose -f docker-compose.build.yml build --no-cache + +# run container image with specified runner (default runner: docker) +run tag=default_tag runner=default_runner: + @echo "Running with '{{runner}}'..." + {{runner}} compose -f docker-compose.build.yml up -d --force-recreate + @# watch -n 1 {{runner}} compose -f docker-compose.build.yml ps + +publish image=default_image runner=default_runner: + @echo "Publishing with '{{runner}}'..." + @# log into gitpot + {{runner}} login gitpot.dev -u $GITPOT_USERNAME -p $GITPOT_PASSWORD + @# push the specified image to the container registry + {{runner}} push {{image}} + @echo -e "\e[1;32mPublished {{image}} successfuly! Use '{{runner}} pull {{image}}' to pull the container.\e[0m" + +# development + +# install dependencies +_install: + yarn install + +# run vite dev server +dev: _install + @echo "Running vite development server..." + yarn run dev --open + +# run vite preview server +preview: _install + @echo "Running vite preview server..." + yarn run build + yarn run preview --open diff --git a/README.md b/README.md index 59ac201..2084e2d 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,23 @@ Feel free to explore! You're welcome to contribute to this website if you have a Lunivity account (see homepage for details if registrations aren't open).
Once you fork and clone the repository, follow the next steps. +If you have `just` installed, setting up is pretty easy: + +```bash +# setup dependencies and run dev server +just + +# you can also run `just dev` +just dev + +# to build and preview a webpage, run `just preview` +just preview +``` + +View a list of all possible `just` recipes with `just -l`. + +Otherwise, if you don't already have or don't want to install `just`, you can run the commands manually: + ```bash # install dependencies yarn install @@ -23,16 +40,31 @@ Once you've made your changes, you can create a Pull Request and I'll make sure ## Building -To create a production version of this website: +To create a production version of this website without docker: ```bash yarn run build ``` +To build a docker container image with `just`: + +```bash +# build and run container image with docker +just build + +# build with podman +just build podman + +# clean, build, and run container image with docker or podman +just all +just all podman +``` + You can preview the production build with `yarn run preview`. ## License You can view this project's source code license [here](./LICENSE). -All assets created by me are Copyright (c) 2019-2024 Sangelo unless otherwise stated. +All assets (images, logos, etc.) created by me (Sangelo) are Copyright (c) 2019-2024 Sangelo unless otherwise stated.
+Brand logos and icons (such as Discord, Github, YouTube, etc.) are trademarked by and copyright of their respective owners. diff --git a/docker-compose.build.yml b/docker-compose.build.yml index 0fb6a7f..60767d7 100644 --- a/docker-compose.build.yml +++ b/docker-compose.build.yml @@ -1,7 +1,6 @@ -version: '3.8' - services: web: + image: gitpot.dev/sangelo/website:${TAG} build: context: . dockerfile: Dockerfile