Skip to content

Commit

Permalink
feat: Refactor Dockerfile to better support new DevOps scenarios with…
Browse files Browse the repository at this point in the history
… Container App Jobs (#18)
  • Loading branch information
Krusty93 committed Mar 1, 2024
1 parent f8ab1c6 commit 993856b
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 219 deletions.
118 changes: 118 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
**/.dockerignore
**/.git
apps/onboarding-ms/.idea/.gitignore
**/bin
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md

**/.idea
.idea
**/.mvn
.mvn

**/target

# Created by .ignore support plugin (hsz.mobi)
### Maven template
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
### Java template
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests
48 changes: 33 additions & 15 deletions .github/workflows/beta-docker-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,64 @@ name: Beta docker on dev branch

on:
push:
# Sequence of patterns matched against refs/heads
branches-ignore:
- 'main'
paths-ignore:
- 'CODEOWNERS'
- '**.md'
- '.**'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
release:
name: Beta docker on dev branch
runs-on: ubuntu-22.04

steps:

- name: Checkout
id: checkout
# from https://github.com/actions/checkout/commits/main
uses: actions/checkout@1f9a0c22da41e6ebfa534300ef656657ea2c6707
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #v4.1.1
with:
persist-credentials: false
fetch-depth: 0

- name: Setup Docker buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

- name: Log in to the Container registry
id: docker_login
# from https://github.com/docker/login-action/commits/master
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ghcr.io
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
uses: docker/metadata-action@dbef88086f6cef02e264edb7dbf63250c17cef6c # v5.5.0
id: meta
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=beta-${{ github.ref_name }}
labels:
org.opencontainers.image.title=${{ env.IMAGE_NAME }}-beta
org.opencontainers.image.description=GitHub self hosted runner
org.opencontainers.image.authors=PagoPA
org.opencontainers.image.url=github.com/pagopa/${{ github.repository }}
org.opencontainers.image.source=https://github.com/pagopa/${{ github.repository }}

- name: Build and push Docker image
id: docker_build_push
# from https://github.com/docker/build-push-action/commits/master
uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository }}:beta-${{ github.ref_name }}
labels: |
maintainer=https://pagopa.it
org.opencontainers.image.source=https://github.com/${{ github.repository }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=min
platforms: linux/amd64,linux/arm64
46 changes: 31 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Release

on:
# Trigger the workflow on push on the main branch
push:
branches:
- main
Expand All @@ -10,23 +9,26 @@ on:
- '**.md'
- '.**'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
release:
name: Release
runs-on: ubuntu-22.04

steps:

- name: Checkout
id: checkout
# from https://github.com/actions/checkout/commits/main
uses: actions/checkout@1f9a0c22da41e6ebfa534300ef656657ea2c6707
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #v4.1.1
with:
persist-credentials: false
fetch-depth: 0

- name: Release
id: release
# from https://github.com/cycjimmy/semantic-release-action/commits/main
uses: cycjimmy/semantic-release-action@bdd914ff2423e2792c73475f11e8da603182f32d
with:
semantic_version: 18.0.0
Expand All @@ -39,24 +41,38 @@ jobs:
- name: Log in to the Container registry
id: docker_login
if: steps.release.outputs.new_release_published == 'true'
# from https://github.com/docker/login-action/commits/master
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ghcr.io
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
uses: docker/metadata-action@dbef88086f6cef02e264edb7dbf63250c17cef6c # v5.5.0
id: meta
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest
type=raw,value=v${{ steps.release.outputs.new_release_version }}
labels:
org.opencontainers.image.title=${{ env.IMAGE_NAME }}
org.opencontainers.image.description=GitHub self hosted runner
org.opencontainers.image.authors=PagoPA
org.opencontainers.image.url=github.com/PagoPA/${{ github.repository }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}

- name: Build and push Docker image
id: docker_build_push
if: steps.release.outputs.new_release_published == 'true'
# from https://github.com/docker/build-push-action/commits/master
uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:v${{ steps.release.outputs.new_release_version }}
labels: |
maintainer=https://pagopa.it
org.opencontainers.image.source=https://github.com/${{ github.repository }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=min
platforms: linux/amd64,linux/arm64
55 changes: 34 additions & 21 deletions .github/workflows/trivy.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,65 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Docker security scan

on:
push:
branches: [ "main", "master" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main", "master" ]
schedule:
- cron: '00 07 * * *'

permissions:
contents: read
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
name: Build
runs-on: ubuntu-22.04
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
name: Build
runs-on: ubuntu-22.04

steps:

- name: Checkout code
# from https://github.com/actions/checkout/commits/main
uses: actions/checkout@1f9a0c22da41e6ebfa534300ef656657ea2c6707

- name: Build an image from Dockerfile
run: |
docker build -t docker.io/my-organization/my-app:${{ github.sha }} .
- name: Setup Docker buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

- name: Docker meta
uses: docker/metadata-action@dbef88086f6cef02e264edb7dbf63250c17cef6c # v5.5.0
id: meta
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,enable=true,format=long
- name: Build Docker image
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
with:
context: .
load: true
push: false
tags: ${{ steps.meta.outputs.tags }}
file: Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=min
platforms: linux/amd64

- name: Run Trivy vulnerability scanner
# from https://github.com/aquasecurity/trivy-action/commits/master
uses: aquasecurity/trivy-action@d63413b0a4a4482237085319f7f4a1ce99a8f2ac
uses: aquasecurity/trivy-action@84384bd6e777ef152729993b8145ea352e9dd3ef # v0.17.0
with:
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
format: 'template'
template: '@/contrib/sarif.tpl'
image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:sha-${{ github.sha }}'
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
timeout: '10m0s'

- name: Upload Trivy scan results to GitHub Security tab
# from https://github.com/github/codeql-action/commits/main
uses: github/codeql-action/upload-sarif@f0a12816612c7306b485a22cb164feb43c6df818
uses: github/codeql-action/upload-sarif@592977e6ae857384aa79bb31e7a1d62d63449ec5 # v2.16.3
with:
sarif_file: 'trivy-results.sarif'
Loading

0 comments on commit 993856b

Please sign in to comment.