Compare commits

..

21 commits

Author SHA1 Message Date
3f637dbab3 Automated building and deployment process with Docker (#2)
Reviewed-on: https://gitpot.dev/sangelo/website/pulls/2
2024-04-03 12:10:51 +00:00
e0112466ce Merge branch 'main' into docker 2024-04-03 12:10:00 +00:00
7e19be55b1 [c] Update README with up-to-date just commands 2024-04-03 13:08:42 +02:00
ef5bc8a670 [c] add description label to dockerfile 2024-04-03 12:59:24 +02:00
4ecf1f1de6 [c] modify workflow if-statement to work in SH
All checks were successful
Build and push docker image / deploy (push) Successful in 42s
2024-04-03 12:46:25 +02:00
88950724c9 [c] re-create tag var in publish container task
All checks were successful
Build and push docker image / deploy (push) Successful in 42s
2024-04-03 12:43:07 +02:00
1bc627e890 [c] debug workflow vars
Some checks failed
Build and push docker image / deploy (push) Failing after 40s
2024-04-03 12:41:20 +02:00
2ccdfe1550 [c] try fixing tag variable
Some checks failed
Build and push docker image / deploy (push) Failing after 39s
2024-04-03 12:39:23 +02:00
e2b394a6eb [c] update tag refs to work properly
Some checks failed
Build and push docker image / deploy (push) Failing after 46s
2024-04-03 12:32:42 +02:00
309e066319 [c] Mount the docker socket into the container
Some checks failed
Build and push docker image / deploy (push) Failing after 32s
2024-04-03 11:44:00 +02:00
1b8431f234 [c] force workflow to use proper image
Some checks failed
Build and push docker image / deploy (push) Failing after 32s
2024-04-03 11:25:12 +02:00
b697c19342 [c] Update Justfile Path in workflow
Some checks failed
Build and push docker image / deploy (push) Failing after 5s
2024-04-03 11:19:26 +02:00
f3c9b5b994 [c] Update workflow working directory
Some checks failed
Build and push docker image / deploy (push) Failing after 5s
2024-04-03 11:13:50 +02:00
d6243574e6 [a] Initial build workflow
Some checks failed
Build and push docker image / deploy (push) Failing after 26s
2024-04-03 11:05:30 +02:00
fb13312485 [c] Update Justfile env variables for publishing 2024-04-03 11:05:16 +02:00
968673e8cd [c] Remove broken colorisation 2024-04-02 23:18:57 +02:00
6374398544 [c] Fix Justfile errors, Dockerfile removes build image now 2024-04-02 20:25:10 +02:00
df92de60da [a] Initial Justfile build script 2024-04-02 17:42:33 +02:00
ebaa9d5783 [a] add podman build script 2024-03-26 13:57:52 +01:00
34ebf48f0b Specify Licenses in more detail 2024-03-22 13:03:42 +01:00
0aa9dffd75 Initial Docker Automatisation Work 2024-03-22 11:19:46 +01:00
8 changed files with 233 additions and 3 deletions

View file

@ -0,0 +1,48 @@
name: Build and push docker image
# start workflow every time a tag/release is created
on:
push:
tags:
- '*'
jobs:
deploy:
runs-on: ubuntu-latest
container:
image: ghcr.io/catthehacker/ubuntu:act-latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock
defaults:
run:
working-directory: /tmp
# build the docker container
steps:
- name: ✨ Installing just command runner
run: |
# download and extract just to /bin/just
curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /bin
just --help || echo "Error: 'just' wasn't found. Maybe the download failed?"
- name: ⬇️ Checkout Repository
uses: actions/checkout@v4
- name: 🐋 Build Container
run: |
# extract tag name without the prefix
export TAG=$(echo "${{ github.ref }}" | sed 's/refs\/tags\///')
# build the container
just -f /workspace/sangelo/website/Justfile build "${TAG}"
- name: 🐳 Publish Container
run: |
export TAG=$(echo "${{ github.ref }}" | sed 's/refs\/tags\///')
echo "${{ secrets.PUBLISH_TOKEN }}" | docker login gitpot.dev -u sangelo --password-stdin
docker push "gitpot.dev/sangelo/website:${TAG}"
# publish tag latest as well
if echo "${{ github.ref }}" | grep -q "refs/tags/"; then
docker tag "gitpot.dev/sangelo/website:${TAG}" "gitpot.dev/sangelo/website:latest"
docker push "gitpot.dev/sangelo/website:latest"
fi

35
Dockerfile Normal file
View file

@ -0,0 +1,35 @@
# Builder stage
FROM node:20-alpine AS builder
# Set the working directory in the container
WORKDIR /app
# Copy the repository contents into the container
COPY . .
# Install dependencies and build the site. Output directory will be /app/build
RUN yarn install && yarn run build
# Final stage
FROM caddy:2-alpine
# Set the working directory in the container
WORKDIR /web
# Copy the build directory from the builder stage to /web
COPY --from=builder /app/build /web
# Caddyfile configuration to serve files from /web
RUN echo -e ":80 {\n root * /web\n file_server\n}" > /etc/caddy/Caddyfile
# Expose port 80
EXPOSE 80
# Start Caddy with the specified Caddyfile
CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]
# Description for docker container
LABEL description="Sangelo's Space website, packaged as a docker container, with the Caddy webserver."
# Remove intermediate images after build
ONBUILD RUN rm -rf /app

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 -o 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}}'..."
TAG={{tag}} {{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
echo "$GITPOT_TOKEN" | {{runner}} login gitpot.dev -u $GITPOT_USERNAME --password-stdin
@# push the specified image to the container registry
{{runner}} push {{image}}
@echo "Published {{image}} successfuly! Use '{{runner}} pull {{image}}' to pull the container."
# 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,20 @@ 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
```
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,14 +37,44 @@ 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: ### Build locally
To create a production version of this website without docker:
```bash ```bash
# automatically build & preview
just preview
# or, manually build
yarn run build yarn run build
``` ```
You can preview the production build with `yarn run preview`. You can then preview the production build locally with `yarn run preview --open`.
The files will be available in the repo, in the `build/` directory.
### Build with Docker
To build a docker container image with `just`:
```bash
# build and run container image with docker, tag: latest
just build
# build with podman
just build <tag> podman
# clean, build, and run container image with docker, tag: latest
just all
# clean, build, and run container image with podman, tag: dev
just all dev podman
```
You can preview the produced docker build with `just run [tag] [runner]`.
## License ## License
You can view this project's license [here](./LICENSE). You can view this project's source code license [here](./LICENSE).
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.

5
build-podman.sh Executable file
View file

@ -0,0 +1,5 @@
podman compose -f docker-compose.build.yml down && \
#podman compose -f docker-compose.build.yml rm --all && \
podman compose -f docker-compose.build.yml build --no-cache && \
podman compose -f docker-compose.build.yml up -d --force-recreate && \
watch -n 1 podman compose -f docker-compose.build.yml ps

5
build.sh Executable file
View file

@ -0,0 +1,5 @@
sudo docker compose -f docker-compose.build.yml down && \
#sudo docker compose -f docker-compose.build.yml rm --all && \
sudo docker compose -f docker-compose.build.yml build --no-cache && \
sudo docker compose -f docker-compose.build.yml up -d --force-recreate && \
watch -n 1 sudo docker compose -f docker-compose.build.yml ps

9
docker-compose.build.yml Normal file
View file

@ -0,0 +1,9 @@
services:
web:
image: gitpot.dev/sangelo/website:${TAG}
build:
context: .
dockerfile: Dockerfile
no_cache: true
ports:
- "3000:80"

0
docker-compose.yml Normal file
View file