Skip to content

Commit

Permalink
Fix dockerfile lint (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju authored Sep 12, 2024
1 parent c99cca1 commit 3bbf3a2
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 @@ -12,19 +12,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 @@ -37,14 +47,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 wget -O /bin/hadolint https://github.com/hadolint/hadolint/releases/download/v2.8.0/hadolint-Linux-x86_64 && sudo chmod +x /bin/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 "file_exists=true" >> $GITHUB_OUTPUT
else
echo "file_exists=false" >> $GITHUB_OUTPUT
fi
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
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 3bbf3a2

Please sign in to comment.