Skip to content

Commit

Permalink
feat: add build image workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
rancoud committed Jan 3, 2024
1 parent 9104e53 commit 4b6a729
Show file tree
Hide file tree
Showing 22 changed files with 755 additions and 92 deletions.
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ tests/medias/

# Dump for installation
dump-with-anonymous-user.sql
dump-without-anonymous-user.sql
dump-without-anonymous-user.sql

# Examples
docker-examples/
65 changes: 65 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: build

on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
branches:
- main

env:
DOCKERHUB_SLUG: blueprintue/blueprintue-self-hosted-edition
GHCR_SLUG: ghcr.io/blueprintue/blueprintue-self-hosted-edition

jobs:
build:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKERHUB_SLUG }}
${{ env.GHCR_SLUG }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Build Image
uses: docker/bake-action@v4
with:
files: |
./docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
targets: image-all
push: ${{ github.event_name != 'pull_request' }}
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ tests/tests.env.cache.php
# Storage
storage/
tests/storage_test/
docker-examples/storage/

# Medias
www/medias/avatars/
www/medias/blueprints/
tests/medias/
tests/medias/
docker-examples/medias/

# Examples
docker-examples/db/
52 changes: 28 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
FROM crazymax/alpine-s6:3.13 AS base
FROM crazymax/alpine-s6:latest AS base

ENV S6_BEHAVIOR_IF_STAGE2_FAILS="2" \
TZ="UTC" \
PUID="1500" \
PGID="1500"

RUN apk --update --no-cache add \
curl \
nginx \
php7 \
php7-cli \
php7-ctype \
php7-curl \
php7-dom \
php7-exif \
php7-fileinfo \
php7-fpm \
php7-gd \
php7-iconv \
php7-intl \
php7-json \
php7-mbstring \
php7-opcache \
php7-openssl \
php7-pdo \
php7-pdo_mysql \
php7-phar \
php7-session \
php7-sodium \
php7-xml \
php7-zlib \
php \
php-cli \
php-ctype \
php-curl \
php-dom \
php-exif \
php-fileinfo \
php-fpm \
php-gd \
php-iconv \
php-intl \
php-json \
php-mbstring \
php-opcache \
php-openssl \
php-pdo \
php-pdo_mysql \
php-phar \
php-session \
php-sodium \
php-xml \
php-zlib \
mariadb-client \
shadow \
tzdata \
Expand All @@ -46,7 +47,7 @@ RUN apk --update --no-cache add curl \
&& chown -R blueprintue-self-hosted-edition. /opt/blueprintue-self-hosted-edition
COPY app ./app
COPY www ./www
COPY .env.template ./.env
RUN touch .env

FROM base

Expand All @@ -58,4 +59,7 @@ EXPOSE 8000
WORKDIR /opt/blueprintue-self-hosted-edition
VOLUME [ "/opt/blueprintue-self-hosted-edition/storage" ]

COPY cronscript.sh /etc/periodic/15min/crons
CMD [ "crond", "-l", "2", "-f" ]

ENTRYPOINT ["/init"]
70 changes: 18 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@
* \>= MySQL 8 or >= MariaDB 10.6

## How to install?
### Docker Image
| Registry | Image |
|------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------|
| [Docker Hub](https://hub.docker.com/r/blueprintue/blueprintue-self-hosted-edition/) | `blueprintue/blueprintue-self-hosted-edition` |
| [GitHub Container Registry](https://github.com/users/blueprintue/packages/container/package/blueprintue-self-hosted-edition) | `ghcr.io/blueprintue/blueprintue-self-hosted-edition` |

Read [docker-examples](https://github.com/blueprintue/blueprintue-self-hosted-edition/blob/main/docker-examples) about documentation and docker-compose file example.

### FTP / localhost
Download zip file from last [release](https://github.com/blueprintue/blueprintue-self-hosted-edition/releases) or run a `composer install` to have `vendor` folder.
1. copy folders `app`, `storage`, `vendor` and paste **outside** of the public folder of your server
2. copy folder content `www` and paste **inside** the public folder of your server
3. copy `dump-with-anonymous-user.sql` or `dump-without-anonymous-user.sql` and paste file in your database
4. copy `.env.template` and paste file **outside** of the public folder of your server
5. fill values in `.env.template` file with what you need (database and email)
6. rename `.env.template` to `.env`
6. rename `.env.template` to `.env` (see [Configuration explanations](#configuration-explanations))
7. done

The `public folder` means what your http server can show you, usually it is called is `www` or `public_html`
Expand All @@ -41,9 +50,9 @@ blueprintUE self-hosted edition is like blueprintUE but without

## GDPR
Because GDPR you will need to:
* fill contact email
* fill page privacy policy
* fill page terms of service
* fill contact email [(in .env file)](https://github.com/blueprintue/blueprintue-self-hosted-edition/blob/main/.env.template#L46)
* fill page privacy policy [(in /app/views/www/pages/privacy_policy.php)](https://github.com/blueprintue/blueprintue-self-hosted-edition/blob/main/app/views/www/pages/privacy_policy.php#L25)
* fill page terms of service [(in /app/views/www/pages/terms_of_service.php)](https://github.com/blueprintue/blueprintue-self-hosted-edition/blob/main/app/views/www/pages/terms_of_service.php#L25)

## Configuration explanations
### .env file
Expand Down Expand Up @@ -74,10 +83,10 @@ Because GDPR you will need to:
| SESSION_REMEMBER_SAMESITE | NO | string | Strict | None \| Lax \| Strict | security policies on how cookies are shared, Lax is mandatory for Twitter OAuth |

#### Host
| Parameter | Mandatory | Type | Default value | Specific values | Description |
| --------- | --------- | ------ | -------------- | --------------- |-----------------------------------------------------|
| HOST | YES | string | | | hostname (e.g. blueprintue-self-hosted-edition.com) |
| HTTPS | YES | bool | | | use for detect scheme (http or https) |
| Parameter | Mandatory | Type | Default value | Specific values | Description |
| --------- | --------- | ------ | -------------- | --------------- |------------------------------------------------------|
| HOST | YES | string | | | hostname (e.g. blueprintue-self-hosted-edition.test) |
| HTTPS | YES | bool | | | use for detect scheme (http or https) |

#### Site
| Parameter | Mandatory | Type | Default value | Specific values | Description |
Expand Down Expand Up @@ -225,7 +234,7 @@ After you can launch dev environment
```shell
cd .dev
touch .env
docker-compose up --build
docker-compose up -d --build --force-recreate
```

### Neard / Wamp / Old school
Expand All @@ -236,46 +245,3 @@ You have to update your `hosts` file those values
```

Follow [How to install](#how-to-install).

## How to test
`docker buildx bake test` create image
`docker run --rm -v $(pwd)/coverage:/src/coverage -e XDEBUG_MODE=coverage --network host blueprintue-self-hosted-edition:test test` launch tests

## Docker
### Buildx
* `docker buildx bake` create image-local
* `docker buildx bake validate` launch 2 subtasks vendor-update && vendor-validate
* `docker buildx bake vendor-validate` check if there is a drift with composer.lock
* `docker buildx bake lint` check if code is matching with lint rules
* `docker buildx bake test` end 2 end testing
* `docker buildx bake image` create a docker image for registry
* `docker buildx bake image-local` create a local docker image

### Docker-compose
`docker-compose build && docker-compose run lib composer ci` for launching tests

### Run image-local
`docker buildx bake && docker run --rm -it -p 8000:8000 blueprintue-self-hosted-edition:local`

### Env variables
#### Rootfs
##### User rights
* `PUID` user id
* `PGID` group id

##### Timezone
* `TZ` timezone (by default: UTC)

##### PHP-FPM
* `MEMORY_LIMIT` memory limit (by default: 256M)
* `POST_MAX_SIZE` post max size (by default: 16M)
* `UPLOAD_MAX_SIZE` upload max size (by default: 16M)

##### OPCache
* `OPCACHE_ENABLE` opcache enable (by default: 1)
* `OPCACHE_MEM_SIZE` opcache memory consumption (by default: 128)

##### Nginx
* `REAL_IP_FROM` real ip from (by default: 0.0.0.0/32)
* `REAL_IP_HEADER` real ip header (by default: X-Forwarded-For)
* `LOG_IP_VAR` log ip var (by default: remote_addr)
17 changes: 17 additions & 0 deletions cronscript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env sh
# purge sessions
echo "Job started (purge sessions): $(date)"
curl --silent http://localhost:8000/cron/purge_sessions/ &>/dev/null
echo "Job started: $(date)"
# purge users not confirmed
echo "Job started (purge users not confirmed): $(date)"
curl --silent http://localhost:8000/cron/purge_users_not_confirmed/ &>/dev/null
echo "Job started: $(date)"
# set soft delete anonymous private blueprints
echo "Job started (set soft delete anonymous private blueprints): $(date)"
curl --silent http://localhost:8000/cron/set_soft_delete_anonymous_private_blueprints/ &>/dev/null
echo "Job started: $(date)"
# purge deleted blueprints
echo "Job started (purge deleted blueprints): $(date)"
curl --silent http://localhost:8000/cron/purge_deleted_blueprints/ &>/dev/null
echo "Job started: $(date)"
19 changes: 16 additions & 3 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variable "PHP_VERSION" {
default = "7.4"
default = "8.2"
}

target "php-version" {
Expand All @@ -8,6 +8,10 @@ target "php-version" {
}
}

target "docker-meta-action" {
tags = ["blueprintue-self-hosted-edition:local"]
}

group "default" {
targets = ["image-local"]
}
Expand Down Expand Up @@ -44,11 +48,20 @@ target "test" {
}

target "image" {
inherits = ["ghaction-docker-meta"]
inherits = ["docker-meta-action"]
dockerfile = "./Dockerfile"
}

target "image-local" {
inherits = ["image"]
output = ["type=docker"]
}
}

target "image-all" {
inherits = ["image"]
platforms = [
"linux/amd64",
"linux/arm/v7",
"linux/arm64",
]
}
Loading

0 comments on commit 4b6a729

Please sign in to comment.