157 lines
4.3 KiB
YAML
157 lines
4.3 KiB
YAML
---
|
|
name: ciandcd
|
|
|
|
on:
|
|
# we want pull requests so we can build(test) but not push to image registry
|
|
pull_request:
|
|
branches:
|
|
- 'main'
|
|
# only build when important files change
|
|
paths-ignore:
|
|
# - 'README.md'
|
|
# - '.github/workflows/linter.yml'
|
|
- '.github/**'
|
|
- 'nginx/**'
|
|
- 'docker-compose.yml'
|
|
- 'docker-compose.dev.yml'
|
|
- 'docker-compose.prod.yml'
|
|
push:
|
|
branches:
|
|
- 'main'
|
|
# only build when important files change
|
|
paths-ignore:
|
|
- '.github/**'
|
|
- 'nginx/**'
|
|
- 'docker-compose.yml'
|
|
- 'docker-compose.dev.yml'
|
|
- 'docker-compose.prod.yml'
|
|
|
|
workflow_dispatch:
|
|
# run whenever we want!
|
|
workflow_call:
|
|
# allow reuse of this workflow in other repos
|
|
inputs:
|
|
dockerhub-enable:
|
|
description: Log in and push to Docker Hub
|
|
required: false
|
|
type: boolean
|
|
default: true
|
|
dockerhub-username:
|
|
description: Docker Hub username
|
|
required: false
|
|
type: string
|
|
default: buzzerburger
|
|
context:
|
|
description: Docker context (path) to start build from
|
|
required: false
|
|
type: string
|
|
default: .
|
|
target:
|
|
description: Build stage to target
|
|
required: false
|
|
type: string
|
|
file:
|
|
description: Name of Dockerfile (in relation to context path)
|
|
required: false
|
|
type: string
|
|
platforms:
|
|
description: Platforms to build for
|
|
required: false
|
|
type: string
|
|
default: linux/amd64,linux/arm64
|
|
image-names:
|
|
description: A list of the account/repo names for docker build
|
|
required: false
|
|
type: string
|
|
default: |
|
|
ghcr.io/buzzerburger/test
|
|
secrets:
|
|
dockerhub-token:
|
|
description: Docker Hub token
|
|
required: false
|
|
|
|
|
|
jobs:
|
|
|
|
laravel-tests:
|
|
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
|
|
with:
|
|
php-version: '8.0'
|
|
- uses: actions/checkout@v3
|
|
- name: Copy app/code/
|
|
run: |
|
|
cd app/code
|
|
composer install
|
|
php artisan test
|
|
|
|
|
|
build-and-push-images:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
-
|
|
name: Checkout
|
|
uses: actions/checkout@v3
|
|
-
|
|
# we need qemu and buildx so we can build multiple platforms later
|
|
name: Set up QEMU
|
|
id: qemu
|
|
uses: docker/setup-qemu-action@v1.2.0
|
|
-
|
|
# BuildKit (used with `docker buildx`) is the best way to build images
|
|
name: Set up Docker Buildx
|
|
id: buildx
|
|
uses: docker/setup-buildx-action@v1
|
|
-
|
|
name: Login to DockerHub
|
|
if: $${{ github.event_name != 'pull_request' }}
|
|
uses: docker/login-action@v1
|
|
with:
|
|
username: ${{ inputs.dockerhub-username }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
-
|
|
name: Login to GHCR
|
|
if: ${{ github.event_name != 'pull_request' }}
|
|
uses: docker/login-action@v1
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GHCR_PAT }}
|
|
|
|
# -
|
|
# name: Docker meta
|
|
# id: docker_meta
|
|
# uses: docker/metadata-action@v3.6.2
|
|
# with:
|
|
# # list of Docker images to use as base name for tags
|
|
# images: ${{ inputs.image-names }}
|
|
# flavor: |
|
|
# latest=false
|
|
# tags: |
|
|
# type=raw,value=latest
|
|
|
|
|
|
-
|
|
# this will build the images, once per platform,
|
|
# then push to both Docker Hub and GHCR
|
|
name: Docker Build and Push
|
|
id: docker_build_and_push
|
|
uses: docker/build-push-action@v2
|
|
with:
|
|
platforms: linux/amd64
|
|
context: app
|
|
builder: ${{ steps.buildx.outputs.name }}
|
|
# it uses github cache API for faster builds:
|
|
# https://github.com/crazy-max/docker-build-push-action/blob/master/docs/advanced/cache.md#cache-backend-api
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
# for an approved pull_request, only push pr-specific tags
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
tags: buzzerburger/test:latest
|
|
# labels: ${{ steps.docker_meta.outputs.labels }}
|
|
-
|
|
name: Show image digest
|
|
run: echo ${{ steps.docker_build_and_push.outputs.digest }}
|