Skip to content

Commit

Permalink
Merge pull request #159 from ncats/removesnyk
Browse files Browse the repository at this point in the history
fix: removed zap & updated runners
  • Loading branch information
vuyyurusri authored Nov 1, 2024
2 parents 247db18 + 53abc96 commit af54313
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 159 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ on:
jobs:
analyze:
name: Analyze
runs-on: [ncatslnghrunpdv04.ncats.nih.gov]
runs-on:
group: ncats-onprem-internal-runners
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
security-events: write
Expand Down
157 changes: 0 additions & 157 deletions .github/workflows/snyk-zap.yml

This file was deleted.

85 changes: 85 additions & 0 deletions .github/workflows/snyk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Define the name of the workflow
name: snyk

# Define variables
env:
DOCKER_REGISTRY: registry.ncats.nih.gov:5000
IMAGE_NAME: pharos-frontend

# Define when the workflow should be triggered (on push to a specific branch and pull requests to the master branch)
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:

# Define the jobs that will be executed as part of the workflow
jobs:
# Job to build and push the Docker image to Docker Hub
Snyk-Docker-Image:
runs-on:
group: ncats-onprem-internal-runners
permissions:
actions: read
contents: read
security-events: write
issues: write

outputs:
build_version: ${{ steps.get_build_version.outputs.build_version }}
RUNNER: ${{ runner.name }}

steps:
# Step 1: Checkout repository
- name: Checkout code
uses: actions/checkout@v4

# Step 2: Generate Build Version Number
- name: Generate Build Version Number
id: GET_BUILD_VERSION
run: |
# Get the last recorded date from the environment variable
LAST_DATE=$(date -d "$LAST_BUILD_DATE" +'%Y-%m-%d' 2>/dev/null || echo "")
# Get the current date
CURRENT_DATE=$(date +'%Y-%m-%d')
echo "Last recorded date: $LAST_DATE"
echo "Current date: $CURRENT_DATE"

# Check if it's a new day
if [ "$LAST_DATE" != "$CURRENT_DATE" ]; then
# Reset BUILDS_TODAY to 0 for the new day
BUILDS_TODAY=0
echo "Resetting BUILDS_TODAY to 0 for the new day"
else
# Calculate the number of builds today
BUILDS_TODAY=$(seq -f v$GITHUB_RUN_NUMBER.%g $(($GITHUB_RUN_NUMBER - 1)) | wc -l)
echo "Incrementing BUILDS_TODAY"
fi

# Store the current date for the next run
echo "LAST_BUILD_DATE=$CURRENT_DATE" >> $GITHUB_ENV

# Generate the build version with the number of builds today
BUILD_VERSION_GENERATED=$(date +v%Y.%m%d.$BUILDS_TODAY)
echo "Generated Build Version: $BUILD_VERSION_GENERATED"
echo "BUILD_VERSION=$BUILD_VERSION_GENERATED" >> $GITHUB_ENV
echo "BUILD=true" >> $GITHUB_ENV
echo "::set-output name=build_version::$BUILD_VERSION_GENERATED"

# Step 4: Build a Docker image
- name: Build a Docker image
run: docker build --no-cache -f ./Dockerfile --build-arg BUILD_VERSION=$BUILD_VERSION -t $DOCKER_REGISTRY/$IMAGE_NAME:$BUILD_VERSION .

# Step 5: Run Snyk to check Docker image for vulnerabilities
- name: Run Snyk to check Docker image for vulnerabilities
continue-on-error: true
uses: snyk/actions/docker@master
id: docker-image-scan
env:
SNYK_TOKEN: ${{ secrets.SNYK_CLI }}
with:
command: monitor
image: $DOCKER_REGISTRY/$IMAGE_NAME:$BUILD_VERSION
args: "--file=Dockerfile"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN npm install --legacy-peer-deps
ENV NODE_OPTIONS --max-old-space-size=8192
RUN npm run build:ssr

FROM node:20-alpine
FROM node:20.15.1-alpine

WORKDIR /app
COPY --from=buildContainer /app/package.json /app
Expand Down

0 comments on commit af54313

Please sign in to comment.