From 01cfe2e358e381b6af5bad1c5d87310be1857893 Mon Sep 17 00:00:00 2001 From: Yuta Matsumura Date: Sat, 23 Sep 2023 22:45:08 +0900 Subject: [PATCH] create container workflow --- .github/workflows/php-cakephp5-container.yml | 92 ++++++++++++++++++++ php/cakephp5/Dockerfile | 43 +++++++++ 2 files changed, 135 insertions(+) create mode 100644 .github/workflows/php-cakephp5-container.yml create mode 100644 php/cakephp5/Dockerfile diff --git a/.github/workflows/php-cakephp5-container.yml b/.github/workflows/php-cakephp5-container.yml new file mode 100644 index 0000000..c22839b --- /dev/null +++ b/.github/workflows/php-cakephp5-container.yml @@ -0,0 +1,92 @@ +# https://book.cakephp.org/5/en/installation.html +name: PHP CakePHP5 Container + +on: + push: + branches: [ main ] + paths: + - 'php/cakephp5/**' + workflow_dispatch: + +env: + PHP_VERSION: '8.2.x' + WORKING_DIRECTORY: php/cakephp5 + PACKAGE_NAME: php-app + ARCHIVE_NAME: cakephp5.zip + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }}-cakephp5 + +permissions: + id-token: write + contents: read + packages: write + +jobs: + build-cakephp5: + runs-on: ubuntu-latest + + defaults: + run: + working-directory: ${{ env.WORKING_DIRECTORY }} + + steps: + - uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + deploy-cakephp5: + runs-on: ubuntu-latest + if: false + needs: build-cakephp5 + environment: + name: 'Production' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v2 + with: + name: ${{ env.PACKAGE_NAME }} + + - name: Az CLI Login + uses: azure/login@v1 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + - name: 'Deploy to Azure Web App' + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: ${{ secrets.AZURE_WEBAPP_NAME }}-container + slot-name: 'Production' + package: ${{ env.ARCHIVE_NAME }} + + - name: Az CLI Logout + run: az logout diff --git a/php/cakephp5/Dockerfile b/php/cakephp5/Dockerfile new file mode 100644 index 0000000..06cf8c1 --- /dev/null +++ b/php/cakephp5/Dockerfile @@ -0,0 +1,43 @@ +# ベースイメージの指定 +FROM php:8.2.10-apache-bullseye + +# 必要なパッケージのインストール +RUN apt-get update && \ + apt-get install -y \ + libicu-dev \ + libpng-dev \ + libzip-dev \ + zip \ + unzip \ + git \ + && \ + rm -rf /var/lib/apt/lists/* + +# PHP拡張のインストール +RUN docker-php-ext-install \ + intl \ + pdo_mysql \ + gd \ + zip + +# Composerのインストール +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +# Apacheの設定 +RUN a2enmod rewrite + +# アプリケーションのコードをコンテナにコピー +COPY . /var/www/html + +# Composerで依存関係をインストール +RUN composer install --no-interaction --no-plugins --no-scripts + +# tmpディレクトリとlogsディレクトリのパーミッションを設定 +RUN chmod -R 777 /var/www/html/tmp +RUN chmod -R 777 /var/www/html/logs + +# コンテナのポートを公開 +EXPOSE 80 + +# Apacheを起動 +CMD ["apache2-foreground"] \ No newline at end of file