Skip to content

Commit 16df3f8

Browse files
committed
Migrate builds to GitHub Actions
1 parent a58dccf commit 16df3f8

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

.github/workflows/deploy.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Test & build Docker image
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
8+
env:
9+
IMAGE_NAME: trafex/php-nginx
10+
11+
jobs:
12+
deploy:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
19+
- name: Build image
20+
run: |-
21+
docker build -t $IMAGE_NAME .
22+
docker tag $IMAGE_NAME:latest $IMAGE_NAME:${{ github.sha }}
23+
24+
- name: Smoke test image
25+
run: |-
26+
docker-compose -f docker-compose.test.yml up -d app
27+
sleep 2
28+
docker-compose -f docker-compose.test.yml run sut
29+
30+
- name: Run Trivy vulnerability scanner
31+
uses: aquasecurity/trivy-action@master
32+
with:
33+
image-ref: '${{ env.IMAGE_NAME }}:${{ github.sha }}'
34+
format: 'template'
35+
template: '@/contrib/sarif.tpl'
36+
output: 'trivy-results.sarif'
37+
38+
- name: Upload Trivy scan results to GitHub Security tab
39+
uses: github/codeql-action/upload-sarif@v1
40+
with:
41+
sarif_file: 'trivy-results.sarif'
42+
43+
- name: Login to Docker Hub
44+
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
45+
uses: docker/login-action@v1
46+
with:
47+
username: ${{ secrets.DOCKERHUB_USERNAME }}
48+
password: ${{ secrets.DOCKERHUB_TOKEN }}
49+
50+
- name: Push latest image
51+
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
52+
run: |-
53+
docker push $IMAGE_NAME:latest
54+
55+
- name: Push tagged image
56+
if: contains(github.ref, 'refs/tags/v')
57+
run: |-
58+
docker push $IMAGE_NAME:$GITHUB_TAG

0 commit comments

Comments
 (0)