Skip to content

Commit

Permalink
Lint and build hadolint and trivy moved from Dockerfile to separate w…
Browse files Browse the repository at this point in the history
…orkflows CI/CD Github Actions main.yml
  • Loading branch information
XOwlPost committed Mar 17, 2024
1 parent 94e6895 commit bac742b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 84 deletions.
98 changes: 14 additions & 84 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,104 +1,34 @@

# Use Miniconda base image
FROM continuumio/miniconda3

Check failure on line 2 in .devcontainer/Dockerfile

View workflow job for this annotation

GitHub Actions / lint-dockerfiles

DL3006 warning: Always tag the version of an image explicitly

# Install Node.js version 20.9.0 (correcting the command)
# Install Node.js and Yarn
RUN conda install -c conda-forge nodejs=20.9.0

# Install Yarn (using npm, which comes with Node.js)
RUN npm install -g yarn

Check failure on line 6 in .devcontainer/Dockerfile

View workflow job for this annotation

GitHub Actions / lint-dockerfiles

DL3059 info: Multiple consecutive `RUN` instructions. Consider consolidation.

Check failure on line 6 in .devcontainer/Dockerfile

View workflow job for this annotation

GitHub Actions / lint-dockerfiles

DL3016 warning: Pin versions in npm. Instead of `npm install <package>` use `npm install <package>@<version>`

# Copy both the environment.yml for Conda and package.json (and yarn.lock if available) for Yarn
# Copy environment specification and JS dependencies definition
COPY environment.yml /tmp/environment.yml
COPY package.json yarn.lock* /tmp/

# Use the environment.yml to create the Conda environment
# Create Conda environment
RUN conda env create -f /tmp/environment.yml

# Make RUN commands use the new environment
SHELL ["conda", "run", "-n", "pre-commit-env", "/bin/bash", "-c"]

RUN pip install checkov terrascan

SHELL ["docker run --rm -i hadolint/hadolint < Dockerfile"]

SHELL ["docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/Library/Caches:/root/.cache/ aquasec/trivy image [my-frontend-app] " ]

# Install JavaScript dependencies with Yarn
RUN cd /tmp && yarn install

# Copy the installed JavaScript dependencies (and other necessary files) into the working directory
COPY . /app
WORKDIR /app

# The code below ensures that the environment is activated on startup
# Activate the Conda environment in bashrc for interactive sessions
RUN echo "conda activate pre-commit-env" >> ~/.bashrc

# (Optional) Install JupyterLab in the Conda environment if you need it
RUN conda run -n pre-commit-env pip install jupyterlab

# Set the default command for the container. Adjust as needed.
CMD ["conda", "run", "-n", "pre-commit-env", "your-command-here"]

name: Lint and Build

on:
push:
branches:
- main
- feature/**
pull_request:

jobs:
lint-dockerfiles:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Install dependencies within the environment
RUN conda run -n pre-commit-env pip install checkov terrascan jupyterlab

# Lint Dockerfile in root directory
- name: Lint Root Dockerfile
uses: hadolint/hadolint-action@v1.5.0
with:
dockerfile: ./Dockerfile

# Lint Dockerfile in .devcontainer directory
- name: Lint Devcontainer Dockerfile
uses: hadolint/hadolint-action@v1.5.0
with:
dockerfile: ./.devcontainer/Dockerfile

build:
needs: lint-dockerfiles
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Build Docker Image from Root
run: |
docker build -t my-app:latest .

- name: Build Docker Image from .devcontainer
run: |
docker build -f ./.devcontainer/Dockerfile -t my-devcontainer:latest .

# Use Miniconda base image
FROM continuumio/miniconda3

# Install dependencies, etc.

# Copy your application's source code and the entrypoint script
# Install JavaScript dependencies
COPY . /app
COPY entrypoint.sh /usr/local/bin/entrypoint.sh

# Set the working directory
WORKDIR /app
RUN cd /tmp && yarn install

Check failure on line 24 in .devcontainer/Dockerfile

View workflow job for this annotation

GitHub Actions / lint-dockerfiles

DL3003 warning: Use WORKDIR to switch to a directory

Check failure on line 24 in .devcontainer/Dockerfile

View workflow job for this annotation

GitHub Actions / lint-dockerfiles

DL3060 info: `yarn cache clean` missing after `yarn install` was run.

# Make the entrypoint script executable
RUN chmod +x /usr/local/bin/entrypoint.sh

# Set the entrypoint to run your script
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
# Copy the rest of your application's source code
COPY . /app

# Set the default command for the container
CMD ["conda", "run", "-n", "pre-commit-env", "your-start-command-here"]

# Expose any ports your application uses (e.g., for a web server)
# Expose any necessary ports
EXPOSE 8888

40 changes: 40 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# name: Lint and Build

on:
push:
branches:
- main
- feature/**
pull_request:

jobs:
lint-dockerfiles:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

# Lint Dockerfile in root directory
- name: Lint Root Dockerfile
uses: hadolint/hadolint-action@v1.5.0
with:
dockerfile: ./Dockerfile

# Lint Dockerfile in .devcontainer directory
- name: Lint Devcontainer Dockerfile
uses: hadolint/hadolint-action@v1.5.0
with:
dockerfile: ./.devcontainer/Dockerfile

build:
needs: lint-dockerfiles
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Build Docker Image from Root
run: |
docker build -t my-app:latest .
- name: Build Docker Image from .devcontainer
run: |
docker build -f ./.devcontainer/Dockerfile -t my-devcontainer:latest .

1 comment on commit bac742b

@vercel
Copy link

@vercel vercel bot commented on bac742b Mar 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployment failed with the following error:

The `vercel.json` schema validation failed with the following message: `images.remotePatterns[0].port` should NOT be shorter than 1 characters

Learn More: https://vercel.com/docs/concepts/projects/project-configuration

Please sign in to comment.