Skip to content

Commit

Permalink
Merge pull request #2 from jembi/CU-86c0zbfdg_dockerise_mediator
Browse files Browse the repository at this point in the history
Cu 86c0zbfdg dockerise mediator
  • Loading branch information
drizzentic authored Nov 15, 2024
2 parents ccccd93 + 2dfa2f5 commit 2e9e049
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 12 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build & Push Climate Mediator image

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

jobs:
build-and-push:
environment: dockerhub
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

30 changes: 30 additions & 0 deletions .github/workflows/scan-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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'

14 changes: 14 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Run Climate Mediator 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

12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:16-alpine

WORKDIR /usr/src/app

COPY . .

RUN npm run build


EXPOSE 3000

CMD [ "node", "dist/index.js" ]
30 changes: 18 additions & 12 deletions tests/services/mediator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,25 @@ describe('Mediator Service', () => {
});
});

// Make the actual request to register
const response = await fetch('https://localhost:8080/mediators', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({}),
}).catch((err) => {
console.error('Fetch error:', err);
throw err;
// Use the existing nock scope to make the request
const response = await new Promise((resolve) => {
https
.request(
'https://localhost:8080/mediators',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
},
(res) => {
resolve(res);
}
)
.end(JSON.stringify({}));
});

// Assert the response status
expect(response.status).to.equal(401);
// Ensure the mocked request was made
expect(scope.isDone()).to.be.true;
});
});

0 comments on commit 2e9e049

Please sign in to comment.