Skip to content

Commit

Permalink
Add SNYK scan to build image
Browse files Browse the repository at this point in the history
  • Loading branch information
RMcVelia committed Jan 6, 2025
1 parent 72406d7 commit 5d05102
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 13 deletions.
22 changes: 13 additions & 9 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ jobs:
name: Image build and push
runs-on: ubuntu-latest
outputs:
image_name_tag: ${{ steps.build_image.outputs.ghcr_image_name_tag }}
docker-image-tag: ${{ steps.build-image.outputs.tag }}
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/build-image
id: build_image
- name: Build and push docker image
id: build-image
uses: DFE-Digital/github-actions/build-docker-image@master
with:
github_username: ${{ github.actor }}
github_token: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
github-token: ${{ secrets.GITHUB_TOKEN }}
context: .
docker-repository: ghcr.io/dfe-digital/access-your-teaching-qualifications
max-cache: true
reuse-cache: true
snyk-token: ${{ secrets.SNYK_TOKEN }}

deploy_review_app:
name: Deploy to review environment
Expand All @@ -58,7 +62,7 @@ jobs:
id: deploy
with:
environment: review
image-tag: ${{ github.sha }}
image-tag: ${{ needs.build_image.outputs.docker-image-tag }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
pull-request-number: ${{ github.event.number }}

Expand Down Expand Up @@ -113,7 +117,7 @@ jobs:
id: deploy
with:
environment: ${{ matrix.environment }}
image-tag: ${{ github.sha }}
image-tag: ${{ needs.build_image.outputs.docker-image-tag }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}

deploy_production:
Expand All @@ -135,5 +139,5 @@ jobs:
id: deploy
with:
environment: production
image-tag: ${{ github.sha }}
image-tag: ${{ needs.build_image.outputs.docker-image-tag }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
41 changes: 41 additions & 0 deletions .github/workflows/build-nocache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build No Cache

on:
workflow_dispatch:
schedule:
- cron: '30 12 * * 0'
# Will run once a week on Sunday afternoon

jobs:
build-no-cache:
env:
DOCKER_REPOSITORY: ghcr.io/dfe-digital/access-your-teaching-qualifications
outputs:
docker-image-tag: ${{ steps.build-image.outputs.tag }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
name: Checkout

- name: Build without cache and push docker image
id: build-image
uses: DFE-Digital/github-actions/build-docker-image@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
context: .
docker-repository: ${{ env.DOCKER_REPOSITORY }}
max-cache: true
reuse-cache: false
snyk-token: ${{ secrets.SNYK_TOKEN }}

- name: Notify slack on failure
uses: rtCamp/action-slack-notify@master
if: ${{ failure() }}
with:
SLACK_USERNAME: CI Deployment
SLACK_COLOR: failure
SLACK_ICON_EMOJI: ':github-logo:'
SLACK_TITLE: 'Build failure'
SLACK_MESSAGE: ':alert: Rebuild docker cache failure :sadparrot:'
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# production: runs the actual app

# Build builder image
FROM ruby:3.3.0-alpine as builder
FROM ruby:3.3.0-alpine AS builder

# RUN apk -U upgrade && \
# apk add --update --no-cache gcc git libc6-compat libc-dev make nodejs \
Expand Down Expand Up @@ -62,16 +62,16 @@ RUN rm -rf node_modules log/* tmp/* /tmp && \
find /usr/local/bundle/gems -name "*.html" -delete

# Build runtime image
FROM ruby:3.3.0-alpine as production
FROM ruby:3.3.0-alpine AS production

# The application runs from /app
WORKDIR /app

ENV RAILS_ENV=production

# Add the commit sha to the env
ARG GIT_SHA
ENV GIT_SHA=$GIT_SHA
ARG COMMIT_SHA
ENV GIT_SHA=$COMMIT_SHA
ENV SHA=$GIT_SHA

# Add the timezone (prod image) as it's not configured by default in Alpine
Expand Down

0 comments on commit 5d05102

Please sign in to comment.