-
Notifications
You must be signed in to change notification settings - Fork 37
135 lines (119 loc) · 4.11 KB
/
ci.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
name: CI
on:
# Build the nightly version at 8:20 AM UTC
schedule:
- cron: "20 8 * * *"
# For all pushes to the main branch run the tests and push the image to the
# GitHub Container Registry under an edge tag
push:
branches:
- master
# For all PRs to the main branch run the tests
pull_request:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
env:
DOCKER_IMAGE: oanhnn/laravel-echo-server
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setting up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- 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 test
id: docker_test
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
context: .
file: ./Dockerfile
pull: true
load: true
tags: ${{ env.DOCKER_IMAGE }}:test
- name: Test with sqlite
run: |
sed -i "s|oanhnn/laravel-echo-server:.*|oanhnn/laravel-echo-server:test|g" ./sqlite.yml
docker-compose -f sqlite.yml up -d
sleep 10s
docker-compose -f sqlite.yml ps
curl --silent --show-error --fail http://127.0.0.1:6001/example.io/socket.io.js
docker-compose -f sqlite.yml down
working-directory: ./examples
- name: Run with docker
run: |
sed -i "s|oanhnn/laravel-echo-server:.*|oanhnn/laravel-echo-server:test|g" ./redis.yml
docker-compose -f redis.yml up -d
sleep 10s
docker-compose -f redis.yml ps
curl --silent --show-error --fail http://127.0.0.1:6001/socket.io/socket.io.js
docker-compose -f redis.yml down
working-directory: ./examples
push:
runs-on: ubuntu-latest
needs: [ 'test' ]
if: github.event_name != 'pull_request'
env:
DOCKER_IMAGE: ghcr.io/oanhnn/laravel-echo-server
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Prepare
id: prepare
run: |
VERSION=test
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=edge
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [ "${{ github.event_name }}" = "push" ]; then
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Setting up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- 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: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
context: .
file: ./Dockerfile
pull: true
push: true
tags: ${{ steps.prepare.outputs.tags }}