Skip to content

feat: update all project data #2

feat: update all project data

feat: update all project data #2

Workflow file for this run

name: webserver-CI
on:
push:
branches:
- main
paths:
- '06-webserver/**' # Any change in this path, make trigger build action.
- '.github/workflows/webserver-ci.yaml'
env:
REPO_APP: 'mqtt-webserver'
SLACK_CHANNEL: 'builds-and-ci'
SLACK_MSG_COLOR: '#0092ff'
BUILD_CONTEXT: './06-webserver'
VULN_SEVERITY: 'CRITICAL'
VULN_TIMEOUT_SCAN: '2m0s'
VULN_OUTPUT_TYPE: 'table'
VULN_OUTPUT_FILE: 'mqtt-webserver_vuln_scan.txt'
COMMITER_NAME: 'AutoCommit'
jobs:
webserver-CI_build-docker-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Generate new version with Semantic-Version
id: nversion
run: |
commit_message=$(git log --format=%B -n 1 ${{ github.sha }})
version=$(curl -s "https://hub.docker.com/v2/repositories/jpradoar/${{ env.REPO_APP }}/tags/?page_size=2" | jq -r '.results[].name'|sort -M|grep -v latest)
X=$(echo $version|cut -d. -f1)
Y=$(echo $version|cut -d. -f2)
Z=$(echo $version|cut -d. -f3)
custom_version=$(echo $X.$Y.$Z)
if [[ $commit_message == *major:* ]]; then
echo "version actual:" $version
NuevaVersion=$(($X+1)).0.0
elif [[ $commit_message == *minor:* ]]; then
NuevaVersion=$X.$(($Y+1)).0
elif [[ $commit_message == *patch:* ]]; then
NuevaVersion=$X.$Y.$(($Z+1))
else
NuevaVersion="latest"
fi
echo "NEW_VERSION=$NuevaVersion " >> "$GITHUB_OUTPUT"
- name: Build and push
uses: docker/build-push-action@v4
with:
context: ${{ env.BUILD_CONTEXT }}
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPO_APP }}:${{ steps.nversion.outputs.NEW_VERSION }}
- name: Run Trivy vulnerability scanner
id: vulnscan
uses: aquasecurity/trivy-action@master
with:
image-ref: '${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPO_APP }}:${{ steps.nversion.outputs.NEW_VERSION }}'
format: ${{ env.VULN_FORMAT }}
vuln-type: 'os,library'
severity: ${{ env.VULN_SEVERITY }}
timeout: ${{ env.VULN_TIMEOUT_SCAN }}
output: vuln_scans/${{ env.VULN_OUTPUT_FILE }}
#exit-code: '1'
# - uses: EndBug/add-and-commit@v9
# with:
# message: 'AutoCommit: Add table file'
# add: ./vuln_scans/${{ env.VULN_OUTPUT_FILE }}
# committer_name: ${{ env.COMMITER_NAME }}
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: ${{ env.SLACK_CHANNEL }}
SLACK_COLOR: ${{ env.SLACK_MSG_COLOR }}
SLACK_MESSAGE: 'URL: https://hub.docker.com/repository/docker/${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPO_APP }}'
SLACK_TITLE: ':rocket: GithubAction Build docker image: [ ${{ env.REPO_APP }}:${{ steps.nversion.outputs.NEW_VERSION }} ]'
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}