Skip to content

Commit

Permalink
Merge pull request #5 from leojonathanoh/feature/add-development-and-…
Browse files Browse the repository at this point in the history
…ci-files

Feature: Add development and ci files
  • Loading branch information
leojonathanoh authored Sep 28, 2022
2 parents 86e071d + df21abe commit dba2d40
Show file tree
Hide file tree
Showing 14 changed files with 798 additions and 1 deletion.
51 changes: 51 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name-template: '$RESOLVED_VERSION 🌈'
tag-template: '$RESOLVED_VERSION'
categories:
- title: '🚀 Features'
labels:
- 'feature'
- 'enhancement'
- title: '🐛 Bug Fixes'
labels:
- 'fix'
- 'bugfix'
- 'bug'
- title: '🖊️ Refactors'
labels:
- 'refactor'
- title: '👗 Style'
labels:
- 'style'
- title: '📝 Documentation'
labels:
- 'docs'
- 'documentation'
- title: '🧰 Maintenance'
label: 'chore'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
version-resolver:
major:
labels:
# - 'major'
- 'breaking'
minor:
labels:
# - 'minor'
- 'feature'
- 'enhancement'
- 'refactor'
patch:
labels:
# - 'patch'
- 'fix'
- 'bugfix'
- 'bug'
- 'style'
- 'docs'
- 'documentation'
default: patch
sort-by: title
template: |
## Changes
$CHANGES
219 changes: 219 additions & 0 deletions .github/workflows/ci-master-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
name: ci-master-pr

on:
push:
branches:
- master
tags:
- '**'
pull_request:
branches:
- master
jobs:

build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Display system info (linux)
run: |
set -e
hostname
whoami
cat /etc/*release
lscpu
free
df -h
pwd
docker info
docker version
# See: https://github.com/docker/build-push-action/blob/v2.6.1/docs/advanced/cache.md#github-cache
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Prepare
id: prep
env:
DOCKERHUB_REGISTRY_USER: ${{ secrets.DOCKERHUB_REGISTRY_USER }}
run: |
set -e
# Get 'namespace' and 'project-name' from 'namespace/project-name'
CI_PROJECT_NAMESPACE=$( echo "${{ github.repository }}" | cut -d '/' -f 1 | tr '[:upper:]' '[:lower:]' ) # Lowercase
CI_PROJECT_NAME=$( echo "${{ github.repository }}" | cut -d '/' -f 2 | tr '[:upper:]' '[:lower:]' ) # Lowercase
# Get <branch_name> from refs/heads/<branch_name>, or <tag-name> from refs/tags/<tag_name>. E.g. . E.g. 'master', 'v1.2.3'
REF=$( echo "${GITHUB_REF}" | rev | cut -d '/' -f 1 | rev )
# Get commit hash E.g. 'b29758a'
SHA_SHORT=$( echo "${GITHUB_SHA}" | cut -c1-7 )
# Generate the final tags. E.g. 'master-v1.0.0-alpine' and 'master-b29758a-v1.0.0-alpine'
VARIANT_TAG_WITH_REF="${REF}"
VARIANT_TAG_WITH_REF_AND_SHA_SHORT="${REF}-${SHA_SHORT}"
# Set step output(s)
echo "::set-output name=CI_PROJECT_NAMESPACE::$CI_PROJECT_NAMESPACE"
echo "::set-output name=CI_PROJECT_NAME::$CI_PROJECT_NAME"
# echo "::set-output name=REF::$REF"
# echo "::set-output name=SHA_SHORT::$SHA_SHORT"
# echo "::set-output name=REF_AND_SHA_SHORT::$REF_AND_SHA_SHORT"
# echo "::set-output name=CONTEXT::$VARIANT_BUILD_DIR"
echo "::set-output name=VARIANT_TAG::$VARIANT_TAG"
echo "::set-output name=VARIANT_TAG_WITH_REF::$VARIANT_TAG_WITH_REF"
echo "::set-output name=VARIANT_TAG_WITH_REF_AND_SHA_SHORT::$VARIANT_TAG_WITH_REF_AND_SHA_SHORT"
- name: Login to docker registry
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
run: echo "${DOCKERHUB_REGISTRY_PASSWORD}" | docker login -u "${DOCKERHUB_REGISTRY_USER}" --password-stdin
env:
DOCKERHUB_REGISTRY_USER: ${{ secrets.DOCKERHUB_REGISTRY_USER }}
DOCKERHUB_REGISTRY_PASSWORD: ${{ secrets.DOCKERHUB_REGISTRY_PASSWORD }}

- name: Build nginx (PRs)
id: docker_build_pr_nginx
# Run only on pull requests
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v2
with:
file: Dockerfile.nginx.prod
context: ${{ steps.prep.outputs.CONTEXT }}
platforms: linux/amd64
push: false
tags: |
${{ steps.prep.outputs.CI_PROJECT_NAMESPACE }}/${{ steps.prep.outputs.CI_PROJECT_NAME }}:${{ steps.prep.outputs.VARIANT_TAG_WITH_REF }}-nginx
${{ steps.prep.outputs.CI_PROJECT_NAMESPACE }}/${{ steps.prep.outputs.CI_PROJECT_NAME }}:${{ steps.prep.outputs.VARIANT_TAG_WITH_REF_AND_SHA_SHORT }}-nginx
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Build php (PRs)
id: docker_build_pr_php
# Run only on pull requests
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v2
with:
file: Dockerfile.php.prod
context: ${{ steps.prep.outputs.CONTEXT }}
platforms: linux/amd64
push: false
tags: |
${{ steps.prep.outputs.CI_PROJECT_NAMESPACE }}/${{ steps.prep.outputs.CI_PROJECT_NAME }}:${{ steps.prep.outputs.VARIANT_TAG_WITH_REF }}-php
${{ steps.prep.outputs.CI_PROJECT_NAMESPACE }}/${{ steps.prep.outputs.CI_PROJECT_NAME }}:${{ steps.prep.outputs.VARIANT_TAG_WITH_REF_AND_SHA_SHORT }}-php
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Build and push nginx (master)
id: docker_build_master_nginx
# Run only on master
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v2
with:
file: Dockerfile.nginx.prod
context: ${{ steps.prep.outputs.CONTEXT }}
platforms: 'linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x'
push: true
tags: |
${{ steps.prep.outputs.CI_PROJECT_NAMESPACE }}/${{ steps.prep.outputs.CI_PROJECT_NAME }}:${{ steps.prep.outputs.VARIANT_TAG_WITH_REF }}-nginx
${{ steps.prep.outputs.CI_PROJECT_NAMESPACE }}/${{ steps.prep.outputs.CI_PROJECT_NAME }}:${{ steps.prep.outputs.VARIANT_TAG_WITH_REF_AND_SHA_SHORT }}-nginx
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Build and push php (master)
id: docker_build_master_php
# Run only on master
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v2
with:
file: Dockerfile.php.prod
context: ${{ steps.prep.outputs.CONTEXT }}
platforms: 'linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x'
push: true
tags: |
${{ steps.prep.outputs.CI_PROJECT_NAMESPACE }}/${{ steps.prep.outputs.CI_PROJECT_NAME }}:${{ steps.prep.outputs.VARIANT_TAG_WITH_REF }}-php
${{ steps.prep.outputs.CI_PROJECT_NAMESPACE }}/${{ steps.prep.outputs.CI_PROJECT_NAME }}:${{ steps.prep.outputs.VARIANT_TAG_WITH_REF_AND_SHA_SHORT }}-php
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Build and push nginx(release)
id: docker_build_release_nginx
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v2
with:
file: Dockerfile.nginx.prod
context: ${{ steps.prep.outputs.CONTEXT }}
platforms: 'linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x'
push: true
tags: |
${{ steps.prep.outputs.CI_PROJECT_NAMESPACE }}/${{ steps.prep.outputs.CI_PROJECT_NAME }}:${{ steps.prep.outputs.VARIANT_TAG_WITH_REF }}-nginx
${{ steps.prep.outputs.CI_PROJECT_NAMESPACE }}/${{ steps.prep.outputs.CI_PROJECT_NAME }}:${{ steps.prep.outputs.VARIANT_TAG_WITH_REF_AND_SHA_SHORT }}-nginx
# ${{ steps.prep.outputs.CI_PROJECT_NAMESPACE }}/${{ steps.prep.outputs.CI_PROJECT_NAME }}:nginx
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Build and push php (release)
id: docker_build_release_php
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v2
with:
file: Dockerfile.php.prod
context: ${{ steps.prep.outputs.CONTEXT }}
platforms: 'linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x'
push: true
tags: |
${{ steps.prep.outputs.CI_PROJECT_NAMESPACE }}/${{ steps.prep.outputs.CI_PROJECT_NAME }}:${{ steps.prep.outputs.VARIANT_TAG_WITH_REF }}-php
${{ steps.prep.outputs.CI_PROJECT_NAMESPACE }}/${{ steps.prep.outputs.CI_PROJECT_NAME }}:${{ steps.prep.outputs.VARIANT_TAG_WITH_REF_AND_SHA_SHORT }}-php
${{ steps.prep.outputs.CI_PROJECT_NAMESPACE }}/${{ steps.prep.outputs.CI_PROJECT_NAME }}:php
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: List docker images
run: docker images

- name: Clean-up
run: docker logout
if: always()

update-draft-release:
needs: [build]
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
with:
config-name: release-drafter.yml
publish: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish-draft-release:
needs: [build]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Resolve tag
id: resolve-tag
run: |
# Get <branch_name> from refs/heads/<branch_name>, or <tag-name> from refs/tags/<tag_name>. E.g. . E.g. 'master', 'v1.2.3'
REF=$( echo "${GITHUB_REF}" | rev | cut -d '/' -f 1 | rev )
echo "::set-output name=REF::$REF"
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
with:
config-name: release-drafter.yml
publish: true
name: ${{ steps.resolve-tag.outputs.REF }}
tag: ${{ steps.resolve-tag.outputs.REF }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29 changes: 29 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/src": "${workspaceRoot}/src",
},
"xdebugSettings": {
"max_data": 10000,
"max_children": 10000
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
17 changes: 17 additions & 0 deletions Dockerfile.nginx.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM alpine:latest AS build
ARG TARGETPLATFORM
ARG BUILDPLATFORM
RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM"

# Set permissions for nginx's 'nginx' user
COPY ./src /src
WORKDIR /src
RUN chown -R 101:101 . \
&& find . -type d -exec chmod 750 {} \; \
&& find . -type f -exec chmod 640 {} \;

FROM nginx:1.21-alpine

# Add default configs
COPY config/nginx/nginx.conf /etc/nginx/nginx.conf
COPY --from=build /src /src
22 changes: 22 additions & 0 deletions Dockerfile.php.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM php:7.4-fpm

# opcache
RUN docker-php-ext-install opcache

# mysql PDO
RUN docker-php-ext-install pdo pdo_mysql

# xdebug
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
RUN { \
echo "[xdebug]"; \
echo "zend_extension=xdebug"; \
echo "xdebug.mode=debug"; \
echo "xdebug.start_with_request=yes"; \
echo "xdebug.client_host=host.docker.internal"; \
echo "xdebug.client_port=9000"; \
} > /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini;

RUN php -i
RUN php -m
27 changes: 27 additions & 0 deletions Dockerfile.php.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM alpine:latest AS build
ARG TARGETPLATFORM
ARG BUILDPLATFORM
RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM"

# Set permissions for php-fpm-alpine's 'www-data' user
COPY ./src /src
WORKDIR /src
RUN chown -R 82:82 . \
&& find . -type d -exec chmod 750 {} \; \
&& find . -type f -exec chmod 640 {} \;

FROM php:7.4-fpm

# opcache
RUN docker-php-ext-install opcache

# mysql PDO
RUN docker-php-ext-install pdo pdo_mysql

RUN php -i
RUN php -m

# Add default configs
COPY ./config/php/php-fpm.d/php_fpm_exporter.conf /usr/local/etc/php-fpm.d/php_fpm_exporter.conf
COPY ./config/php/conf.d/php.ini /usr/local/etc/php/conf.d/php.ini
COPY --from=build /src /src
Loading

0 comments on commit dba2d40

Please sign in to comment.