Skip to content

Commit 5f977fe

Browse files
authored
Merge pull request #46 from kduma-OSS/docker-images
Prepare Docker Images
2 parents e0a99eb + 93853dd commit 5f977fe

7 files changed

Lines changed: 300 additions & 0 deletions

File tree

.dockerignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.editorconfig
2+
.env
3+
.gitattributes
4+
.gitignore
5+
.phpstorm.meta.php
6+
.phpunit.result.cache
7+
.dockerignore
8+
_ide_helper.php
9+
_ide_helper_models.php
10+
docker-compose.yml
11+
docker-compose-prod.yml
12+
ngnix.Dockerfile
13+
php.Dockerfile
14+
README.md
15+
rector.php
16+
vendor/*
17+
node_modules/*
18+
public/build/*
19+
bootstrap/cache/*
20+
public/hot/*
21+
public/storage/*
22+
storage/*.key
23+
.env.backup
24+
.env.production
25+
Homestead.json
26+
Homestead.yaml
27+
auth.json
28+
npm-debug.log
29+
yarn-error.log
30+
.fleet
31+
.idea
32+
.vscode
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Docker Images
2+
3+
# This workflow uses actions that are not certified by GitHub.
4+
# They are provided by a third-party and are governed by
5+
# separate terms of service, privacy policy, and support
6+
# documentation.
7+
8+
on:
9+
push:
10+
branches: [ master ]
11+
# Publish semver tags as releases.
12+
tags: [ 'v*.*.*' ]
13+
14+
pull_request:
15+
branches: [ master ]
16+
17+
# Allows you to run this workflow manually from the Actions tab
18+
workflow_dispatch:
19+
20+
env:
21+
# Use docker.io for Docker Hub if empty
22+
REGISTRY: ghcr.io
23+
# github.repository as <account>/<repo>
24+
IMAGE_NAME: ${{ github.repository }}
25+
26+
27+
jobs:
28+
build-and-push-image:
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
include:
33+
- dockerfile: ./ngnix.Dockerfile
34+
image: ghcr.io/kduma-oss/webprint-server/nginx
35+
- dockerfile: ./php.Dockerfile
36+
image: ghcr.io/kduma-oss/webprint-server/fpm
37+
38+
runs-on: ubuntu-latest
39+
permissions:
40+
contents: read
41+
packages: write
42+
# This is used to complete the identity challenge
43+
# with sigstore/fulcio when running outside of PRs.
44+
id-token: write
45+
46+
steps:
47+
- name: Checkout repository
48+
uses: actions/checkout@v3
49+
50+
51+
# Workaround: https://github.com/docker/build-push-action/issues/461
52+
- name: Setup Docker buildx
53+
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
54+
55+
56+
# Login against a Docker registry except on PR
57+
# https://github.com/docker/login-action
58+
- name: Log into registry ${{ env.REGISTRY }}
59+
if: github.event_name != 'pull_request'
60+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
61+
with:
62+
registry: ${{ env.REGISTRY }}
63+
username: ${{ github.actor }}
64+
password: ${{ secrets.GITHUB_TOKEN }}
65+
66+
67+
# Extract metadata (tags, labels) for Docker
68+
# https://github.com/docker/metadata-action
69+
- name: Extract Docker metadata
70+
id: meta
71+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
72+
with:
73+
images: ${{ matrix.image }}
74+
tags: |
75+
type=ref,event=branch
76+
type=ref,event=pr
77+
type=ref,event=tag
78+
type=semver,pattern=v{{version}}
79+
type=semver,pattern=v{{major}}.{{minor}}
80+
type=semver,pattern=v{{major}}
81+
82+
83+
# Build and push Docker image with Buildx (don't push on PR)
84+
# https://github.com/docker/build-push-action
85+
- name: Build and push Docker image
86+
id: build-and-push
87+
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
88+
with:
89+
context: ${{ matrix.context }}
90+
file: ${{ matrix.dockerfile }}
91+
push: ${{ github.event_name != 'pull_request' }}
92+
tags: ${{ steps.meta.outputs.tags }}
93+
labels: ${{ steps.meta.outputs.labels }}
94+
cache-from: type=gha
95+
cache-to: type=gha,mode=max

docker-compose-prod.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
version: "3"
2+
services:
3+
nginx:
4+
build:
5+
context: .
6+
dockerfile: ngnix.Dockerfile
7+
image: ghcr.io/kduma-oss/webprint-server/nginx
8+
restart: always
9+
ports:
10+
- "8080:80"
11+
depends_on:
12+
- php
13+
networks:
14+
- internal
15+
16+
php:
17+
build:
18+
context: .
19+
dockerfile: php.Dockerfile
20+
image: ghcr.io/kduma-oss/webprint-server/fpm
21+
restart: always
22+
networks:
23+
- internal
24+
depends_on:
25+
- db
26+
environment:
27+
- DB_CONNECTION=mysql
28+
- DB_HOST=db
29+
- DB_PORT=3306
30+
- DB_DATABASE=webprint_server
31+
- DB_USERNAME=webprint_server
32+
- DB_PASSWORD=${DB_PASSWORD}
33+
34+
- APP_KEY=${APP_KEY}
35+
36+
db:
37+
image: mysql:8.0
38+
restart: always
39+
environment:
40+
- MYSQL_RANDOM_ROOT_PASSWORD=yes
41+
- MYSQL_DATABASE=webprint_server
42+
- MYSQL_USER=webprint_server
43+
- MYSQL_PASSWORD=${DB_PASSWORD}
44+
networks:
45+
- internal
46+
volumes:
47+
- db_data:/var/lib/mysql
48+
49+
networks:
50+
internal:
51+
driver: bridge
52+
53+
volumes:
54+
db_data: {}

docker/nginx/default.conf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
server {
2+
listen 80;
3+
listen [::]:80;
4+
5+
root /var/www/html/public;
6+
7+
add_header X-Frame-Options "SAMEORIGIN";
8+
add_header X-Content-Type-Options "nosniff";
9+
10+
index index.php;
11+
12+
charset utf-8;
13+
14+
location / {
15+
try_files $uri $uri/ /index.php?$query_string;
16+
}
17+
18+
location = /favicon.ico { access_log off; log_not_found off; }
19+
location = /robots.txt { access_log off; log_not_found off; }
20+
21+
error_page 404 /index.php;
22+
23+
location ~ \.php$ {
24+
include fastcgi_params;
25+
fastcgi_pass php:9000;
26+
fastcgi_index index.php;
27+
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
28+
}
29+
30+
location ~ /\.(?!well-known).* {
31+
deny all;
32+
}
33+
}

docker/php/opcache.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[opcache]
2+
opcache.enable=1
3+
opcache.revalidate_freq=0
4+
opcache.validate_timestamps=0
5+
opcache.max_accelerated_files=10000
6+
opcache.memory_consumption=192
7+
opcache.max_wasted_percentage=10
8+
opcache.interned_strings_buffer=16
9+
opcache.fast_shutdown=1

ngnix.Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM node:19-alpine AS vite_stage
2+
3+
WORKDIR /var/www/html
4+
5+
COPY package.json package-lock.json ./
6+
RUN npm ci
7+
8+
COPY postcss.config.js tailwind.config.js vite.config.js ./
9+
COPY resources ./resources
10+
RUN npm run build
11+
12+
13+
14+
15+
16+
17+
FROM nginx:alpine
18+
19+
WORKDIR /var/www/html
20+
21+
COPY docker/nginx/default.conf /etc/nginx/conf.d
22+
23+
COPY --from=vite_stage /var/www/html/public/build /var/www/html/public/build
24+
25+
COPY ./ /var/www/html/

php.Dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
FROM node:19-alpine AS vite_stage
2+
3+
WORKDIR /var/www/html
4+
5+
COPY package.json package-lock.json ./
6+
RUN npm ci
7+
8+
COPY postcss.config.js tailwind.config.js vite.config.js ./
9+
COPY resources ./resources
10+
RUN npm run build
11+
12+
13+
14+
15+
16+
FROM php:8.1-cli-alpine AS composer_stage
17+
18+
WORKDIR /var/www/html
19+
20+
COPY --from=composer /usr/bin/composer /usr/bin/composer
21+
22+
COPY composer.json composer.lock ./
23+
RUN composer install --ignore-platform-reqs --prefer-dist --no-scripts --no-progress --no-interaction --no-dev --no-autoloader
24+
25+
COPY . ./
26+
RUN composer dump-autoload --optimize --apcu --no-dev
27+
28+
29+
30+
FROM php:8.1-fpm-alpine
31+
32+
WORKDIR /var/www/html
33+
34+
RUN docker-php-ext-install pdo pdo_mysql
35+
RUN docker-php-ext-install opcache
36+
37+
COPY docker/php/opcache.ini /usr/local/etc/php/conf.d/opcache.ini
38+
39+
40+
41+
COPY --from=vite_stage /var/www/html/public/build /var/www/html/public/build
42+
43+
COPY --from=composer_stage /var/www/html/vendor /var/www/html/vendor
44+
COPY --from=composer_stage /var/www/html/bootstrap/cache /var/www/html/bootstrap/cache
45+
46+
COPY . /var/www/html/
47+
48+
RUN chown -R www-data:www-data /var/www/html/storage
49+
50+
51+
ENV APP_ENV=production
52+
ENV APP_DEBUG=false

0 commit comments

Comments
 (0)