Files
tryno10/.github/workflows/docker.yml
T
Workflow config file is invalid. Please check your config file: read workflow: yaml: unmarshal errors: line 161: mapping key "push" already defined at line 156 line 162: mapping key "tags" already defined at line 157
2022-04-08 05:53:15 +05:30

166 lines
4.8 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
builtandtestimages:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.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: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
-
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: |
buzzerburger/test
ghcr.io/buzzerburger/test
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
# target: ${{ inputs.target }}
# file: ${{ inputs.file }}
# 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: Build and push
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: user/app:latest
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
-
name: Show image digest
run: echo ${{ steps.docker_build_and_push.outputs.digest }}