Skip to content

Commit 91a8e14

Browse files
authored
Merge pull request #35 from TrafeX/migrate-github-action
Migrate the Docker build process to GitHub Actions
2 parents 13e5fe6 + b0149f4 commit 91a8e14

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

.github/workflows/deploy.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Test & build Docker image
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
8+
env:
9+
IMAGE_NAME: trafex/wordpress
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 wordpress
27+
docker-compose -f docker-compose.test.yml run sut
28+
29+
- name: Run Trivy vulnerability scanner
30+
uses: aquasecurity/trivy-action@master
31+
with:
32+
image-ref: '${{ env.IMAGE_NAME }}:${{ github.sha }}'
33+
format: 'template'
34+
template: '@/contrib/sarif.tpl'
35+
output: 'trivy-results.sarif'
36+
37+
- name: Upload Trivy scan results to GitHub Security tab
38+
uses: github/codeql-action/upload-sarif@v1
39+
with:
40+
sarif_file: 'trivy-results.sarif'
41+
42+
- name: Login to Docker Hub
43+
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
44+
uses: docker/login-action@v1
45+
with:
46+
username: ${{ secrets.DOCKERHUB_USERNAME }}
47+
password: ${{ secrets.DOCKERHUB_TOKEN }}
48+
49+
- name: Push latest image
50+
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
51+
run: |-
52+
docker push $IMAGE_NAME:latest
53+
54+
- name: Push tagged image
55+
if: contains(github.ref, 'refs/tags/v')
56+
run: |-
57+
docker push $IMAGE_NAME:$GITHUB_TAG

docker-compose.test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ services:
2222
FS_METHOD: direct
2323

2424
sut:
25-
image: alpine:3.10
25+
image: alpine:3.13
2626
depends_on:
2727
- wordpress
2828
command: /tmp/run_tests.sh

0 commit comments

Comments
 (0)