Skip to content

Commit

Permalink
Adds github workflow for tests, scan of images and publishing to dock…
Browse files Browse the repository at this point in the history
…erhub
  • Loading branch information
ItsMurumba committed Nov 11, 2024
1 parent fe72bd9 commit 4748132
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Build and Push jembi/climate-mediator image

on:
push:
tags:
- "*.*.*"
branches:
- "*"

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- run: npm run build

- name: Build and push tag
if: ${{ github.ref_name != 'main' }}
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
push: true
tags: jembi/climate-mediator:${{ github.ref_name }}

- name: Build and push latest
if: ${{ github.ref_name == 'main' }}
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
push: true
tags: jembi/climate-mediator:latest
29 changes: 29 additions & 0 deletions .github/workflows/scan-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Scan latest climate mediator image

on:
schedule:
- cron: '0 5 * * *'

jobs:
scan-images:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Build an image from Dockerfile
run: |
docker build -t jembi/climate-mediator:${{ github.sha }} .
- name: Run trivy vulnerability scanner for the climate mediator image
uses: aquasecurity/trivy-action@master
with:
image-ref: jembi/climate-mediator:${{ github.sha }}
format: 'sarif'
output: 'trivy-results.sarif'

- name: Upload Trivy scan results to Github Security tab
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: 'trivy-results.sarif'
13 changes: 13 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Tests
on: push

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: npm i

- name: Run tests
run: npm run test

0 comments on commit 4748132

Please sign in to comment.