Skip to content

Commit

Permalink
Added Dockerfile and workflow
Browse files Browse the repository at this point in the history
Closes #7
  • Loading branch information
andy5995 committed Nov 20, 2024
1 parent 0787d8b commit 9db3ee4
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/docker-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Test Build-Env Docker Image

on:
pull_request:
branches: master
paths:
- '**Dockerfile'
- '**docker.yml'

jobs:
build-test-env-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build image
run: docker build -t test-image -f docker/Dockerfile .

- name: Build Docker image
run: docker build -t test-image -f docker/Dockerfile ./docker

- name: Run commands in Docker container
run: |
docker run --rm -v ${{ github.workspace }}:/workspace \
-w /workspace \
-u builder \
test-image \
/bin/bash -l -c "sudo mkdir /workspace/build && sudo chmod 777 /workspace/build &&
bun install &&
bun run codegen &&
bun run meson-setup.clang-release &&
meson compile -C build/ vs:executable
"
40 changes: 40 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Build-Env Docker Image

on:
push:
branches: master
paths:
- '**Dockerfile'
- '**docker.yml'
# workflow_dispatch:
# schedule:
# - cron: '30 11 20 */3 *'

env:
REGISTRY_IMAGE: ghcr.io/${{ github.repository_owner }}/vs-fltk

jobs:
build-env-image:
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
file: ./Dockerfile
platforms: ${{ matrix.platform }}
cache-from: type=registry,ref=${{ env.REGISTRY_IMAGE }}:build-env-buildcache
cache-to: type=registry,ref=${{ env.REGISTRY_IMAGE }}:build-env-buildcache,mode=max
40 changes: 40 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM debian:trixie-slim

ARG DEBIAN_FRONTEND=noninteractive
ENV DEBIAN_FRONTEND=$DEBIAN_FRONTEND

RUN \
apt update && apt upgrade -y && \
apt install -y \
build-essential \
ca-certificates \
clang-19 \
cmake \
curl \
freeglut3-dev \
git \
libpng-dev \
libsqlite3-0 \
libsqlitecpp-dev \
libtcc-dev \
lsb-release \
meson \
pkg-config \
sudo \
swiftlang \
unzip \
wget && \
update-ca-certificates -f

RUN useradd -m builder && passwd -d builder
RUN echo "builder ALL=(ALL) ALL" >> /etc/sudoers
WORKDIR /home/builder
USER builder

RUN curl -fsSL https://bun.sh/install | bash
RUN \
echo "export BUN_INSTALL=\"\$HOME/.bun\"" >> $HOME/.profile && \
echo "export PATH=\"\$BUN_INSTALL/bin:\$PATH\"" >> $HOME/.profile

USER root
CMD ["bash", "-l"]
31 changes: 31 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Docker

## Using docker-compose

You may build and test your changes by using the compose file:

docker-compose -f ./docker/docker-compose.yml up

## Entering the build environment

While in the repository root, to enter the environment and be presented with a
shell:

docker run -it --rm -u builder \
-v $PWD:/workspace ghcr.io/KaruroChori/vs-fltk:build-env

This will mount your current directory as */workspace* inside the container.
Your username will be *builder*. By default, you will not have root privileges
(which are not necessary to build and test). However, you can use `sudo` if
you need to run `apt` or any other commands that require root access.

## Getting the image

You can pull the image manually:

docker pull ghcr.io/KaruroChori/vs-fltk:build-env

If you use `docker-compose` or `docker run ...` the image will be pulled
automatically the first time.


19 changes: 19 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3.8'

services:
dev:
image: ghcr.io/KaruroChori/vs-fltk:build-env
container_name: vs-fltk-env
volumes:
- ${PWD}:/workspace
working_dir: /workspace
user: builder
command: >
bash -l -c "
bun install &&
bun run codegen &&
bun run meson-setup.clang-release &&
meson compile -C build/ vs:executable
"
stdin_open: true # Allows interactive mode
tty: true # Allocate a pseudo-TTY
6 changes: 6 additions & 0 deletions docs/for-developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ To run the dev demo where features under development are usually being tested:
bun run vs.example
```

### Docker

A docker image is available that contains all the build dependencies. See
[docker/README.md](https://github.com/KaruroChori/vs-fltk/docker/README.md)

### Patches

Notice: this issue was only observed with `zig` as the backend and cannot be easily reproduced.
Expand Down Expand Up @@ -157,6 +162,7 @@ Exceptions should only be used in those cases when the application **must** stop

As for memory allocations, spawning small dynamic objects is also discouraged. If possible, stack allocations are a better alternative. Arrays with variable length on stack are totally fine to be used in place of local objects allocated on heap.
`std::string` is also highly discouraged, make sure `std::string_view` is used instead whenever possible.
<<<<<<< HEAD

### About log levels

Expand Down

0 comments on commit 9db3ee4

Please sign in to comment.