Skip to content

Commit

Permalink
Dytt image opp til NHN (#43)
Browse files Browse the repository at this point in the history
Bruker i tillegg base-r:main som basis-image for å unngå sårbarheter.

Oppdaterte ellers actions med slik den er satt opp ellers. La blant annet til concurrency, slik at jobber stopper hvis det kommer ny commit
  • Loading branch information
arnfinn authored Oct 11, 2024
1 parent 06b8717 commit 0c61074
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 117 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
schedule:
- cron: '0 21 * * 6' # run every Saturday at 21

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
push_to_registries:
name: Push Docker image to docker hub
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/harbor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Publish Docker image to Harbor
on:
release:
types: [published]
push:
branches:
- main
pull_request:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
env:
IMAGE_NAME: ${{ github.repository }}
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Lint Dockerfile
uses: hadolint/hadolint-action@v3.1.0
with:
dockerfile: "Dockerfile"
- name: R setup
uses: r-lib/actions/setup-r@v2
- name: Build package (tarball)
run: R CMD build .
- name: Prepare tags
id: docker_meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=schedule,pattern=weekly
type=semver,pattern={{version}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Harbor
run: |
echo ${{ secrets.HARBOR_PASSWORD }} | docker login --username ${{ secrets.HARBOR_USERNAME }} --password-stdin ${{ secrets.HARBOR_REGISTRY }}
- name: Build image and push to Harbor
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
tags: ${{ secrets.HARBOR_REGISTRY }}/${{ steps.docker_meta.outputs.tags }}
push: ${{ github.event_name != 'pull_request' }}
cache-from: type=gha
cache-to: type=gha,mode=max
51 changes: 19 additions & 32 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,36 @@
on:
push:
branches: [ "main" ]
branches:
- main
pull_request:
branches: [ "main" ]
branches:
- main

name: lint
name: lintr

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GH_TOKEN }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3

- name: Install unmet sys deps
run: |
sudo apt update
sudo apt install -y --no-install-recommends libcurl4-openssl-dev libgit2-dev libharfbuzz-dev libfribidi-dev
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Cache R packages
uses: actions/cache@v3
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
use-public-rspm: true

- name: Install dependencies
run: |
install.packages(c("remotes", "devtools"))
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("lintr")
shell: Rscript {0}
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::lintr, local::.
needs: lint

- name: Lint
run: |
devtools::load_all()
lintr::lint_package()
run: lintr::lint_package()
shell: Rscript {0}
env:
LINTR_ERROR_ON_LINT: false
78 changes: 18 additions & 60 deletions .github/workflows/r-cmd-check.yml
Original file line number Diff line number Diff line change
@@ -1,98 +1,56 @@
on:
push:
branches: [ "main" ]
branches:
- main
pull_request:
branches: [ "main" ]
branches:
- main

name: R-CMD-check

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-24.04, r: 'release'}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GH_TOKEN }}
GITHUB_PAT: ${{ github.token }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-tinytex@v2

- name: Db unit tests in ubuntu/linux only
if: runner.os != 'Windows'
run: |
if [[ ${{ runner.os }} == Linux ]]; then
echo "GITHUB_ACTIONS_RUN_DB_UNIT_TESTS=true" >> $GITHUB_ENV
else
echo "GITHUB_ACTIONS_RUN_DB_UNIT_TESTS=false" >> $GITHUB_ENV
fi
- name: Set up MySQL, ubuntu only
if: runner.os == 'Linux'
run: |
sudo /etc/init.d/mysql start
mysql -e 'CREATE DATABASE IF NOT EXISTS testdb;' -uroot -proot
- name: Set up system fonts, macOS only
if: runner.os == 'macOS'
run: brew install --cask xquartz

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v3
- uses: r-lib/actions/setup-r-dependencies@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "22.04"))')
- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}
extra-packages: any::rcmdcheck
needs: check

- name: Check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "error", check_dir = "check")
run: |
options(crayon.enabled = TRUE)
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Upload check results
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
49 changes: 26 additions & 23 deletions .github/workflows/vulnerability.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
name: Vulnerability by snyk.io
name: Snyk Container

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: '0 21 * * 1' # run every Monday at 21
- cron: '30 22 * * 5'

permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
snyk:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
runs-on: ubuntu-latest
env:
IMAGE_NAME: ${{ github.repository }}
name: rapadm-snyk
steps:
- uses: actions/checkout@v3
- name: downcase repository name for image
run: |
echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
- uses: actions/checkout@v4
- name: R setup
uses: r-lib/actions/setup-r@v2
- name: Build R package (tarball)
- name: Build package (tarball)
run: R CMD build .
- name: Build a Docker image
run: docker build -t ${IMAGE_NAME} --build-arg GH_PAT=${{ secrets.GITHUB_TOKEN}} .
- name: Build docker image
run: docker build -t rapadm-snyk .
- name: Run Snyk to check Docker image for vulnerabilities
# Snyk can be used to break the build when it detects vulnerabilities.
# In this case we want to upload the issues to GitHub Code Scanning
Expand All @@ -38,17 +32,26 @@ jobs:
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
image: ${IMAGE_NAME}
args: --file=Dockerfile --severity-threshold=critical
image: rapadm-snyk
args: --file=Dockerfile --severity-threshold=high
- name: Upload result to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@v2
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: snyk.sarif
- name: Accept only vulnerability levels below critical
- name: Monitor image in Snyk UI
continue-on-error: true
uses: snyk/actions/docker@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: monitor
image: rapadm-snyk
args: --file=Dockerfile --severity-threshold=high --org=b034af62-43be-40c7-95e8-fdc56d6f3092
- name: Accept only vulnerability levels below high
continue-on-error: false
uses: snyk/actions/docker@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
image: ${IMAGE_NAME}
args: --file=Dockerfile --severity-threshold=critical
image: rapadm-snyk
args: --file=Dockerfile --severity-threshold=high
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM rapporteket/base-r:4.2.2
FROM rapporteket/base-r:main

LABEL maintainer "Are Edvardsen <are.edvardsen@helse-nord.no>"
LABEL maintainer "Arnfinn Hykkerud Steindal <arnfinn.hykkerud.steindal@helse-nord.no>"

Check warning on line 3 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "LABEL key=value" should be used instead of legacy "LABEL key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
LABEL no.rapporteket.cd.enable="true"

ARG GH_PAT
Expand Down

0 comments on commit 0c61074

Please sign in to comment.