[a] Initial Justfile build script

This commit is contained in:
Sangelo 2024-04-02 17:42:33 +02:00
parent ebaa9d5783
commit df92de60da
3 changed files with 119 additions and 4 deletions

84
Justfile Normal file
View file

@ -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

View file

@ -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).<br> You're welcome to contribute to this website if you have a Lunivity account (see homepage for details if registrations aren't open).<br>
Once you fork and clone the repository, follow the next steps. 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 ```bash
# install dependencies # install dependencies
yarn install yarn install
@ -23,16 +40,31 @@ Once you've made your changes, you can create a Pull Request and I'll make sure
## Building ## Building
To create a production version of this website: To create a production version of this website without docker:
```bash ```bash
yarn run build 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`. You can preview the production build with `yarn run preview`.
## License ## License
You can view this project's source code license [here](./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.<br>
Brand logos and icons (such as Discord, Github, YouTube, etc.) are trademarked by and copyright of their respective owners.

View file

@ -1,7 +1,6 @@
version: '3.8'
services: services:
web: web:
image: gitpot.dev/sangelo/website:${TAG}
build: build:
context: . context: .
dockerfile: Dockerfile dockerfile: Dockerfile