generated from yiisoft/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
10 changed files
with
278 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Ignore everything | ||
* | ||
|
||
# except: | ||
|
||
!/config | ||
!/public | ||
!/src | ||
!/vendor | ||
!autoload.php | ||
!configuration.php | ||
!yii | ||
!composer.json | ||
!composer.lock | ||
!.env* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ phpunit.phar | |
|
||
# NPM packages | ||
/node_modules | ||
.env | ||
/.env | ||
|
||
# Codeception | ||
c3.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
.DEFAULT_GOAL := help | ||
|
||
# Run silent. | ||
MAKEFLAGS += --silent | ||
|
||
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) | ||
$(eval $(RUN_ARGS):;@:) | ||
|
||
include docker/.env | ||
|
||
# Current user ID and group ID. | ||
export UID=$(shell id -u) | ||
export GID=$(shell id -g) | ||
|
||
export COMPOSE_PROJECT_NAME=${STACK_NAME} | ||
|
||
up: ## Up the dev environment. | ||
docker compose -f docker/compose.yml -f docker/compose.dev.yml up -d --remove-orphans | ||
|
||
up-build: ## Up the dev environment rebuilding images. | ||
docker compose -f docker/compose.yml -f docker/compose.dev.yml up -d --remove-orphans --build | ||
|
||
down: ## Down the dev environment. | ||
docker compose -f docker/compose.yml -f docker/compose.dev.yml down --remove-orphans | ||
|
||
exec: ## Run a command within the existing container. | ||
docker compose -f docker/compose.yml -f docker/compose.dev.yml exec app $(CMD) $(RUN_ARGS) | ||
|
||
run: ## Run a command within a temporary container. | ||
docker compose -f docker/compose.yml -f docker/compose.dev.yml run --rm --entrypoint $(CMD) app $(RUN_ARGS) | ||
|
||
shell: CMD="/bin/sh" ## Get into container shell. | ||
shell: exec | ||
|
||
yii: CMD="./yii" ## Execute Yii command. | ||
yii: run | ||
|
||
composer: CMD="composer" ## Run Composer. | ||
composer: run | ||
|
||
codecept: CMD="./vendor/bin/codecept" ## Run Codeception. | ||
codecept: run | ||
|
||
psalm: CMD="./vendor/bin/psalm" ## Run Psalm. | ||
psalm: run | ||
|
||
build-prod: ## Build an image. | ||
docker build --file docker/Dockerfile --target prod --pull -t ${IMAGE}:${IMAGE_TAG} . | ||
|
||
push-prod: ## Push image to repository. | ||
docker push ${IMAGE}:${IMAGE_TAG} | ||
|
||
deploy-prod: ## Deploy to production. | ||
docker -H ${PROD_SSH} stack deploy --with-registry-auth -d -c docker/compose.yml -c docker/compose.prod.yml ${STACK_NAME} | ||
|
||
# Output the help for each task, see https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html | ||
.PHONY: help | ||
help: ## This help. | ||
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
STACK_NAME=app | ||
|
||
PROD_HOST=app.example.com | ||
PROD_SSH="ssh://docker-web" | ||
|
||
IMAGE=app | ||
IMAGE_TAG=latest | ||
|
||
DEV_PORT=80 | ||
|
||
# XDEBUG_MODE=develop,debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
FROM composer/composer:latest-bin AS composer | ||
|
||
FROM ghcr.io/shyim/wolfi-php/frankenphp:8.3 AS base | ||
ARG UID=10001 | ||
ARG GID=10001 | ||
RUN <<SH | ||
set -eo pipefail | ||
set -x | ||
|
||
# Add www-data group and user. | ||
addgroup -g ${GID} -S www-data | ||
adduser -u ${UID} -D -S -G www-data www-data | ||
|
||
# Set volume permissions. | ||
mkdir -p /data /config /app/runtime && \ | ||
chown -R www-data:www-data /data /config /app/runtime | ||
|
||
# Install extra packages. | ||
apk add --no-cache \ | ||
php-frankenphp-8.3-opcache \ | ||
php-frankenphp-8.3-mbstring \ | ||
php-frankenphp-8.3-intl \ | ||
php-frankenphp-8.3-dom \ | ||
php-frankenphp-8.3-curl \ | ||
php-frankenphp-8.3-phar \ | ||
php-frankenphp-8.3-openssl \ | ||
php-frankenphp-8.3-xml \ | ||
php-frankenphp-8.3-xmlwriter \ | ||
php-frankenphp-8.3-simplexml \ | ||
php-frankenphp-8.3-pdo | ||
SH | ||
|
||
FROM base AS prod-builder | ||
COPY --from=composer /composer /usr/bin/composer | ||
|
||
COPY .. /app | ||
|
||
RUN --mount=type=cache,target=/tmp/cache \ | ||
<<SH | ||
set -eo pipefail | ||
set -x | ||
|
||
composer install --no-dev --no-progress --no-interaction --classmap-authoritative && \ | ||
rm composer.lock composer.json | ||
SH | ||
|
||
FROM base AS prod | ||
ENV YII_ENV=prod | ||
|
||
COPY --from=prod-builder --chown=www-data:www-data /app /app | ||
USER www-data | ||
|
||
FROM base AS dev | ||
RUN <<SH | ||
set -eo pipefail | ||
set -x | ||
|
||
# Install extra packages for dev only. | ||
apk add --no-cache \ | ||
php-frankenphp-8.3-xdebug | ||
SH | ||
|
||
COPY --from=composer /composer /usr/bin/composer | ||
USER www-data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
services: | ||
app: | ||
build: | ||
dockerfile: docker/Dockerfile | ||
context: .. | ||
target: dev | ||
args: | ||
UID: ${UID} | ||
GID: ${GID} | ||
environment: | ||
XDEBUG_MODE: "${XDEBUG_MODE:-develop}" | ||
YII_ENV: "${YII_ENV:-dev}" | ||
YII_DEBUG: ${YII_DEBUG:-true} | ||
SERVER_NAME: ":80" | ||
restart: unless-stopped | ||
ports: | ||
- "${DEV_PORT:-80}:80" | ||
volumes: | ||
- ../:/app | ||
- ../runtime:/app/runtime | ||
- ${COMPOSER_CACHE_DIR:-~/.cache/composer}:/var/www/.composer | ||
- caddy_data:/data | ||
- caddy_config:/config | ||
tty: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
services: | ||
app: | ||
image: ${IMAGE}:${IMAGE_TAG} | ||
networks: | ||
- caddy_public | ||
volumes: | ||
- runtime:/app/runtime | ||
- caddy_data:/data | ||
- caddy_config:/config | ||
environment: | ||
SERVER_NAME: ":80" | ||
YII_ENV: "${YII_ENV:-prod}" | ||
YII_DEBUG: ${YII_DEBUG:-false} | ||
deploy: | ||
replicas: 2 | ||
update_config: | ||
delay: 10s | ||
parallelism: 1 | ||
order: start-first | ||
failure_action: rollback | ||
monitor: 10s | ||
rollback_config: | ||
parallelism: 0 | ||
order: stop-first | ||
restart_policy: | ||
condition: on-failure | ||
delay: 5s | ||
max_attempts: 3 | ||
window: 120s | ||
labels: | ||
caddy: ${PROD_HOST:-app.example.com} | ||
caddy.reverse_proxy: "{{upstreams 80}}" | ||
|
||
volumes: | ||
runtime: | ||
|
||
networks: | ||
caddy_public: | ||
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
services: | ||
app: &appconfig | ||
extra_hosts: | ||
- "host.docker.internal:host-gateway" | ||
|
||
volumes: | ||
caddy_data: | ||
caddy_config: |