-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (132 loc) · 4.46 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: build-images
on:
workflow_dispatch:
push:
tags:
- "**"
branches:
- "**"
pull_request:
branches:
- master
jobs:
build-and-test:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: homestead
MYSQL_DATABASE: homestead
ports:
- 33306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
registry:
image: registry:2
ports:
- 5000:5000
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
driver-opts: network=host
-
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: Build and push local test image
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64 #,linux/arm/v7,linux/arm64
push: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
target: ci
build-args: |
PHP_VERSION=8.0
tags: |
localhost:5000/${{ github.event.repository.name }}:qa-${{ github.sha }}
-
name: Run tests
uses: addnab/docker-run-action@v3
with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
options: "--network host"
image: localhost:5000/${{ github.event.repository.name }}:qa-${{ github.sha }}
run: rm -fv .env && cp -v .env.github .env && php artisan config:clear && CI=1 APP_ENV=testing ./vendor/bin/phpunit -c phpunit.github.xml
-
name: Get tag
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF##*/}
-
name: Login to DockerHub
if: startsWith(steps.get_version.outputs.VERSION, 'v') || startsWith(steps.get_version.outputs.VERSION, 'qa') || github.ref == 'refs/heads/master'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Retag and publish local QA image
if: startsWith(steps.get_version.outputs.VERSION, 'qa')
uses: akhilerm/[email protected]
with:
src: localhost:5000/${{ github.event.repository.name }}:qa-${{ github.sha }}
dst: |
docker.io/uogsoe/${{ github.event.repository.name }}:${{ steps.get_version.outputs.VERSION }}
-
name: Build and push prod
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64 #,linux/arm/v7,linux/arm64
push: true
target: prod
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
build-args: |
PHP_VERSION=8.0
tags: |
uogsoe/${{ github.event.repository.name }}:prod-${{ github.sha }}
-
name: Build and push versioned tag
if: startsWith(steps.get_version.outputs.VERSION, 'v')
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64 #,linux/arm/v7,linux/arm64
push: true
target: prod
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
build-args: |
PHP_VERSION=8.0
tags: |
docker.io/uogsoe/${{ github.event.repository.name }}:${{ steps.get_version.outputs.VERSION }}
-
name: Create automatic release on new versioned tag
if: startsWith(steps.get_version.outputs.VERSION, 'v')
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
draft: false
prerelease: false
automatic_release_tag: ${{ steps.get_version.outputs.VERSION }}
title: ${{ steps.get_version.outputs.VERSION }}