Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Workflows #1

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8344868
adding initial version of gha worklflows
nmofonseca May 31, 2024
50ccef8
added buildx cache and hub login
nmofonseca May 31, 2024
c350f40
added qemu and mutliarch build
nmofonseca May 31, 2024
699f1e5
added qemu and mutliarch build
nmofonseca May 31, 2024
7c16665
added docker metadata action for tagging and versioning
nmofonseca Jun 1, 2024
50fd768
Forgot to change docker build to include labels and tags from docker …
nmofonseca Jun 1, 2024
94f9cf0
Added PR comment to include the tag in the comments section of the PR
nmofonseca Jun 1, 2024
f35b657
added permissions to allow comments on the PR
nmofonseca Jun 1, 2024
c21e0eb
added trivy cve scanning
nmofonseca Jun 1, 2024
023732a
trivy scanning fixing
nmofonseca Jun 1, 2024
44800ff
added trivy cve scanning
nmofonseca Jun 1, 2024
a3b9fdd
added trivy cve scanning
nmofonseca Jun 1, 2024
7e15365
adding context to build
nmofonseca Jun 1, 2024
5818de4
Removed context and added build with export to docker to make image a…
nmofonseca Jun 1, 2024
fe42e97
Removed target stage that didn't exist in DockerFile
nmofonseca Jun 1, 2024
f93bb49
Changed back to pushing only when is merge to main, reverted that by …
nmofonseca Jun 1, 2024
4a08306
Trying to fix buildx cache busting by using the same tags for all the…
nmofonseca Jun 1, 2024
5e76f14
Trying to fix buildx cache busting by using the same tags for all the…
nmofonseca Jun 1, 2024
b26169b
Trying to fix buildx cache busting by using the same tags for all the…
nmofonseca Jun 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions .github/workflows/image-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
---
name: Test image build

on:
push:
branches:
- main
pull_request:

jobs:
build-image:
name: Build image
runs-on: ubuntu-latest

# Without this it fails to write comments in the PR
permissions:
pull-requests: write # needed to create and update comments in PRs

steps:
# Setup QEMU for multi-arch builds
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

# Adding Docker Buildx cache
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# Adding docker meta data for tagging and versioning
# Moved to the beguining to avoid busting the cache
- name: Docker Metadata for Final Image Build
id: docker_meta
uses: docker/metadata-action@v5
with:
images: |
nmofonseca/nettools
flavor: |
latest=false
tags: |
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
type=ref,event=pr
type=ref,event=branch
type=semver,pattern={{version}}

# Build for security scanning with Trivy
- name: Build and export to Docker
uses: docker/build-push-action@v5
with:
push: false
load: true # Export to Docker Engine rather than pushing to a registry
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=gha,scope=imagecve
cache-to: type=gha,mode=max,scope=imagecve
platforms: linux/amd64


# Run CVE scanning with Trivy
- name: Run Trivy for all CVEs (non-blocking)
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ steps.docker_meta.outputs.tags }}
exit-code: 0
format: table

# Adding docker hub login
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Adding docker build, won't push if it's a PR
- name: Docker build
uses: docker/build-push-action@v5
with:
push: ${{ github.event_name != 'pull_request' }}
platforms: linux/amd64,linux/arm64
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=gha,scope=imagefinal
cache-to: type=gha,mode=max,scope=imagefinal


## Totally optional, but if you want to add the image tags to the PR comments you can use the following steps
# If PR, put image tags in the PR comments
# from https://github.com/marketplace/actions/create-or-update-comment
- name: Find comment for image tags
uses: peter-evans/find-comment@v3
if: github.event_name == 'pull_request'
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Docker image tag(s) pushed

# If PR, put image tags in the PR comments
- name: Create or update comment for image tags
uses: peter-evans/create-or-update-comment@v4
if: github.event_name == 'pull_request'
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Docker image tag(s) pushed:
```text
${{ steps.docker_meta.outputs.tags }}
```

Labels added to images:
```text
${{ steps.docker_meta.outputs.labels }}
```
edit-mode: replace
42 changes: 20 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,26 @@

FROM debian:stable-slim

RUN <<EOF
apt-get update
apt upgrade -y
apt-get install -y \
curl \
dnsutils \
iproute2 \
iputils-ping \
net-tools \
nmap \
tcpdump \
traceroute \
mtr \
iperf3 \
netcat-openbsd \
apache2-utils \
telnet \
redis-tools
rm -rf /var/lib/apt/lists/*
apt-get clean
useradd -ms /bin/bash nettools
EOF
RUN apt-get update && apt upgrade -y && apt-get install -y curl \
dnsutils \
iproute2 \
iputils-ping \
net-tools \
nmap \
tcpdump \
traceroute \
mtr \
iperf3 \
netcat-openbsd \
apache2-utils \
telnet \
redis-tools \
liburi-perl \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean \
&& useradd -ms /bin/bash nettools

ADD --chmod=755 https://raw.githubusercontent.com/memcached/memcached/master/scripts/memcached-tool /usr/local/bin/memcached-tool

USER nettools

Expand Down