Skip to content

Commit

Permalink
Fix dockerfile lint
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed Sep 11, 2024
1 parent 965d991 commit db1f199
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 19 deletions.
38 changes: 19 additions & 19 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,29 @@ ENV DOTNET_SDK_VERSION=8.0
ENV NODE_VERSION=18

# Install additional OS packages and .NET SDK
RUN apt-get update && apt-get install -y --no-install-recommends \
# hadolint ignore=DL3008
RUN wget --progress=dot:giga https://packages.microsoft.com/config/debian/$DEBIAN_VERSION/packages-microsoft-prod.deb -O packages-microsoft-prod.deb \
&& dpkg -i packages-microsoft-prod.deb \
&& rm packages-microsoft-prod.deb \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
dotnet-sdk-$DOTNET_SDK_VERSION \
git \
apt-transport-https \
curl \
wget
wget \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

RUN wget https://packages.microsoft.com/config/debian/$DEBIAN_VERSION/packages-microsoft-prod.deb -O packages-microsoft-prod.deb \
&& dpkg -i packages-microsoft-prod.deb \
&& rm packages-microsoft-prod.deb \
&& apt-get update \
&& apt-get install -y --no-install-recommends dotnet-sdk-$DOTNET_SDK_VERSION
# Install n package manager and use it to install the latest Node.js and npm
RUN npm install -g n@latest && n $NODE_VERSION \
&& npm install -g npm@latest

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=dialog

RUN apt-get clean -y && rm -rf /var/lib/apt/lists/*
# Set the default shell to bash
SHELL ["/bin/bash", "-c"]

# Switch to the node user
USER node
Expand All @@ -34,14 +44,4 @@ RUN dotnet tool install --global GitVersion.Tool
RUN printf "\nalias gitversion=\"dotnet-gitversion\"\n" >> /home/node/.bashrc

# Switch back to root user to install global npm packages
USER root

# Install n package manager and use it to install the latest Node.js and npm
RUN npm install -g n && n $NODE_VERSION \
&& npm install -g npm@latest

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=dialog

# Set the default shell to bash
SHELL ["/bin/bash", "-c"]
#USER root
47 changes: 47 additions & 0 deletions .github/workflows/dockerfile-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Lint Dockerfile

on:
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest

# cSpell: ignore hadolint .devcontainer sarif codeql
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install Hadolint
run: sudo apt-get update && sudo apt-get install -y hadolint

- name: Create testResults directory
run: mkdir -p testResults

- name: Lint Dockerfile
run: hadolint .devcontainer/Dockerfile --failure-threshold warning --format sarif > testResults/hadolint-results.sarif
continue-on-error: true

- name: Check if SARIF file exists
id: check_sarif
run: |
if [ -f testResults/hadolint-results.sarif ]; then
echo "::set-output name=file_exists::true"
else
echo "::set-output name=file_exists::false"
fi
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v2
if: always() && steps.check_sarif.outputs.file_exists == 'true'
with:
sarif_file: testResults/hadolint-results.sarif

- name: Upload testResults
uses: actions/upload-artifact@v2
if: always() && steps.check_sarif.outputs.file_exists == 'true'
with:
name: hadolint-results
path: testResults/hadolint-results.sarif

0 comments on commit db1f199

Please sign in to comment.