Skip to content

Commit

Permalink
Docker イメージを作成する
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Oct 27, 2022
1 parent 354b8cd commit c3b5152
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 63 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
vendor
.git
var
node_modules
bin/.phpunit
147 changes: 91 additions & 56 deletions .github/workflows/dockerbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,25 @@ name: Testing dockerbuild
on:
push:
paths:
- 'Dockerfile'
- 'dockerbuild/*'
- 'docker-compose*.yml'
- '.github/workflows/dockerbuild.yml'
pull_request:
paths:
- 'Dockerfile'
- 'dockerbuild/*'
- 'docker-compose*.yml'
- '.github/workflows/dockerbuild.yml'
- '**'
- '!*.md'
release:
types: [ published ]
env:
REGISTRY: ghcr.io

jobs:
dockerbuild:
name: dockerbuild
runs-on: ${{ matrix.operating-system }}
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
operating-system: [ ubuntu-18.04 ]
php: [ 7.4 ]
php: [ '7.3', '7.4' ]
db: [ pgsql ]
group: [ admin01 ]
include:
Expand All @@ -30,72 +29,108 @@ jobs:
database_server_version: 14
- group: admin01
app_env: 'codeception'
# - group: admin02
# app_env: 'codeception'
# - group: admin03
# app_env: 'codeception'
# - group: front
# app_env: 'codeception'
# - group: installer
# app_env: 'install'

- php: '7.3'
tag: '7.3-apache'
- php: '7.4'
tag: '7.4-apache'
steps:
- name: downcase REPO
run: |
echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}-php" >> ${GITHUB_ENV}
- name: Checkout
uses: actions/checkout@master
## Used when creating multi-platform images
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v2
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2
- if: ${{ matrix.php >= 7.1 && matrix.php <= 7.3 }}
run: |
echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV}
- if: ${{ matrix.php >= 7.4 }}
run: |
echo "GD_OPTIONS=--with-freetype --with-jpeg" >> ${GITHUB_ENV}
- name: docker build
run: docker compose build
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v1
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
# set latest tag for default branch
type=raw,value=${{ matrix.php }}-apache,prefix=,enable={{is_default_branch}}
type=ref,event=branch,prefix=${{ matrix.php }}-apache-
type=ref,event=tag,prefix=${{ matrix.php }}-apache-
type=ref,event=pr,prefix=${{ matrix.php }}-apache-pr-
- name: Setup PHP
uses: nanasess/setup-php@master
- name: Build and export to Docker
uses: docker/build-push-action@v3
with:
php-version: ${{ matrix.php }}
context: .
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
TAG=${{ matrix.tag }}
GD_OPTIONS=${{ env.GD_OPTIONS }}
- name: composer install
run: composer install --dev --no-interaction -o --apcu-autoloader
- name: Setup to EC-CUBE
env:
APP_ENV: ${{ matrix.app_env }}
DATABASE_URL: ${{ matrix.database_url }}
DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
REGISTRY: ${{ env.REGISTRY }}
IMAGE_NAME: ${{ env.IMAGE_NAME }}
TAG: ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
run: |
docker compose -f docker-compose.yml -f docker-compose.pgsql.yml up -d --wait
sed -i 's!APP_ENV: "dev"!APP_ENV: "prod"!g' docker-compose.yml
docker compose -f docker-compose.yml -f docker-compose.pgsql.yml up -d --wait
- name: setup-chromedriver
uses: nanasess/setup-chromedriver@master
# - name: setup-chromedriver
# uses: nanasess/setup-chromedriver@master

- name: Run chromedriver
run: |
export DISPLAY=:99
chromedriver --url-base=/wd/hub &
echo ">>> Started chrome-driver"
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
echo ">>> Started xvfb"
# - name: Run chromedriver
# run: |
# export DISPLAY=:99
# chromedriver --url-base=/wd/hub &
# echo ">>> Started chrome-driver"
# sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
# echo ">>> Started xvfb"

# - name: Codeception
# env:
# APP_ENV: ${{ matrix.app_env }}
# DATABASE_URL: ${{ matrix.database_url }}
# DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
# MAILER_URL: 'smtp://127.0.0.1:1025'
# GROUP: ${{ matrix.group }}
# SYMFONY_DEPRECATIONS_HELPER: weak
# run: |
# echo "APP_ENV=${APP_ENV}" > .env
# vendor/bin/codecept -vvv run acceptance --env chrome,github_action_docker -g ${GROUP}
## see https://docs.github.com/ja/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#publishing-a-package-using-an-action

- name: Push Docker image
uses: docker/build-push-action@v3
if: success()
with:
context: .
push: true
# platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
TAG=${{ matrix.tag }}
GD_OPTIONS=${{ env.GD_OPTIONS }}
- name: Codeception
env:
APP_ENV: ${{ matrix.app_env }}
DATABASE_URL: ${{ matrix.database_url }}
DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
MAILER_URL: 'smtp://127.0.0.1:1025'
GROUP: ${{ matrix.group }}
SYMFONY_DEPRECATIONS_HELPER: weak
run: |
echo "APP_ENV=${APP_ENV}" > .env
vendor/bin/codecept -vvv run acceptance --env chrome,github_action_docker -g ${GROUP}
- name: Upload evidence
if: failure()
uses: actions/upload-artifact@v2
Expand Down
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM php:7.4-apache-bullseye
ARG TAG=7.4-apache-bullseye
FROM php:${TAG}
ARG GD_OPTIONS="--with-freetype --with-jpeg"

ENV APACHE_DOCUMENT_ROOT /var/www/html

Expand Down Expand Up @@ -33,7 +35,7 @@ RUN apt update \
;

RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \
&& docker-php-ext-configure gd ${GD_OPTIONS} \
&& docker-php-ext-install -j$(nproc) zip gd mysqli pdo_mysql opcache intl pgsql pdo_pgsql \
;

Expand Down Expand Up @@ -65,6 +67,7 @@ RUN curl -sS https://getcomposer.org/installer \
| php \
&& mv composer.phar /usr/bin/composer

RUN composer selfupdate --2.2
RUN composer config -g repos.packagist composer https://packagist.jp

COPY . ${APACHE_DOCUMENT_ROOT}
Expand All @@ -76,4 +79,4 @@ RUN find ${APACHE_DOCUMENT_ROOT} \( -path ${APACHE_DOCUMENT_ROOT}/vendor -prune
| xargs -0 chmod g+s \
;

HEALTHCHECK --interval=10s --timeout=5s --retries=30 CMD pgrep apache
HEALTHCHECK --interval=10s --timeout=5s --retries=30 CMD pgrep apache
3 changes: 3 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ version: '3'

services:
ec-cube:
environment:
USER_ID: ${UID:-}
GROUP_ID: ${GID:-}
volumes:
- ".:/var/www/html:cached"
1 change: 1 addition & 0 deletions docker-compose.mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
environment:
DATABASE_URL: "mysql://dbuser:secret@mysql/eccubedb"
DATABASE_SERVER_VERSION: 5.7
DATABASE_CHARSET: 'utf8mb4'

mysql:
image: mysql:5.7
Expand Down
1 change: 1 addition & 0 deletions docker-compose.pgsql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
environment:
DATABASE_URL: "postgres://dbuser:secret@postgres/eccubedb"
DATABASE_SERVER_VERSION: 14
DATABASE_CHARSET: 'utf8'

postgres:
image: postgres:14
Expand Down
9 changes: 6 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ volumes:
services:
### ECCube4 ##################################
ec-cube:
build:
context: .
### ローカルでビルドする場合は以下のコマンドを使用します
## docker build -t ec-cube --no-cache --pull --build-arg TAG=7.4-apache-4.1 .
## docker tag ec-cube ghcr.io/ec-cube/ec-cube-php:7.4-apache-4.1
image: ${REGISTRY:-ghcr.io}/${IMAGE_NAME:-ec-cube/ec-cube-php}:${TAG:-7.4-apache-4.1}
ports:
- 8080:80
- 4430:443
Expand All @@ -35,7 +37,8 @@ services:
APP_DEBUG: 1
DATABASE_URL: "sqlite:///var/eccube.db"
DATABASE_SERVER_VERSION: 3
MAILER_URL: "smtp://mailcatcher:1025"
DATABASE_CHARSET: 'utf8'
MAILER_DSN: "smtp://mailcatcher:1025"
ECCUBE_AUTH_MAGIC: "<change.me>"
# TRUSTED_HOSTS: '^127.0.0.1$$,^localhost$$'
# ECCUBE_LOCALE: "ja"
Expand Down
7 changes: 7 additions & 0 deletions dockerbuild/docker-php-entrypoint
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/bin/sh
set -e

if [ -n "${USER_ID}" ]; then
usermod -u ${USER_ID} -o www-data
fi
if [ -n "${GROUP_ID}" ]; then
groupmod -g ${GROUP_ID} www-data
fi

if [ ! -d /var/www/html/vendor/bin ]; then
composer install \
--no-scripts \
Expand Down

0 comments on commit c3b5152

Please sign in to comment.