Update build.yml - add SNYK #22
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and test | |
on: | |
workflow_dispatch: # Enables the workflow to be triggered manually | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository code | |
uses: actions/checkout@v4 | |
- name: Install Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install dependencies | |
run: yarn install | |
- name: Run yarn lint | |
run: yarn eslint . | |
- name: Start the server | |
run: | | |
yarn start & | |
sleep 5 | |
curl http://localhost:3000/animals || echo "Server not running" | |
- name: Run tests | |
run: yarn test | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: ./Dockerfile | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/webapp:latest | |
push: true | |
snyk: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Run Snyk to check Docker images for vulnerabilities | |
uses: snyk/actions/docker@master | |
env: | |
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | |
with: | |
image: taisc/webapp | |
args: --severity-threshold=high |