From 45c98d7a25beb0937959dde05673cda5dff75df3 Mon Sep 17 00:00:00 2001 From: Rise Erpelding Date: Mon, 18 Sep 2023 13:31:15 -1000 Subject: [PATCH] chore: create docker deployment workflow --- .dockerignore | 1 - .github/workflows/deploy.docker.yml | 54 +++++++++++++++++++++++++++++ Dockerfile | 12 ++++++- docker-compose.yml | 4 ++- 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/deploy.docker.yml diff --git a/.dockerignore b/.dockerignore index 234d895..fab0048 100644 --- a/.dockerignore +++ b/.dockerignore @@ -15,7 +15,6 @@ node_modules package-lock.json package.json php.ini -plugins src tasks test diff --git a/.github/workflows/deploy.docker.yml b/.github/workflows/deploy.docker.yml new file mode 100644 index 0000000..88e06cc --- /dev/null +++ b/.github/workflows/deploy.docker.yml @@ -0,0 +1,54 @@ +name: Build Docker Image + +on: + push: + branches: [main] + workflow_dispatch: + +jobs: + deploy: + if: ${{ vars.DEPLOY_WITH_DOCKER }} + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x] + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Install npm dependencies + run: npm ci + + - name: Install custom plugin npm dependencies + run: npm run plugins:install + + - name: Install PHP dependencies with Composer + uses: php-actions/composer@v6 + with: + php_version: '8.1' + version: 2.x + + - name: Run tests + run: npm test + + - name: Build theme + run: npm run build:prod + + - name: 'Login to GitHub Container Registry' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{github.actor}} + password: ${{secrets.GH_TOKEN}} + + - name: 'Build Inventory Image' + run: | + docker build . --tag ghcr.io/sparkbox/sparkpress:latest + docker push ghcr.io/sparkbox/sparkpress:latest diff --git a/Dockerfile b/Dockerfile index 5576354..d2e51b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ -FROM php:8.1-apache-buster +FROM php:8.1-apache-buster as dev + +LABEL org.opencontainers.image.source=https://github.com/sparkbox/sparkpress-wordpress-starter # When changings, also change in .circleci/config.yml ENV WP_VERSION=6.3.1 @@ -36,3 +38,11 @@ RUN find /var/www/ -type f -exec chmod 644 {} \; # make the linters executable so we can run them from containers RUN chmod +x vendor/bin/phpcs RUN chmod +x vendor/bin/twigcs + +FROM dev as prod + +COPY theme /var/www/html/wp-content/themes/sparkpress-theme +COPY plugins /var/www/html/wp-content/plugins +COPY wp-configs/wp-config.php /var/www/html/wp-config.php +COPY wp-configs/php.ini /var/www/html/php.ini +COPY wp-configs/.htaccess /var/www/html/.htaccess diff --git a/docker-compose.yml b/docker-compose.yml index a424128..a231ff6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,9 @@ version: '3.7' services: web: - build: . + build: + context: . + target: dev container_name: sparkpress ports: - '8000:80'