Skip to content

Merge pull request #7 from pangolin-do-golang/cicd #35

Merge pull request #7 from pangolin-do-golang/cicd

Merge pull request #7 from pangolin-do-golang/cicd #35

Workflow file for this run

name: Build Aplication
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
Package:
name: Build Test And Push Image
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS Credentials 2
uses: aws-actions/configure-aws-credentials@v4
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
with:
aws-region: us-east-1
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
role-to-assume: arn:aws:iam::637423374452:role/Terrafor-iac
- uses: benjlevesque/[email protected]
id: short-sha
with:
length: 7
- name: Setup GoLang
uses: actions/setup-go@v3
with:
go-version: '1.23.3'
- name: Build And Test
shell: bash
run: |
go test -short -cover ./internal/... -coverprofile=coverage.out
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
SHA: ${{ steps.short-sha.outputs.sha }}
with:
projectBaseDir: ./
args: >
-Dsonar.projectVersion=${{ env.SHA }}
-Dsonar.language=go
-Dsonar.qualitygate.wait=true
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build, Tag, Docker Image
env:
REGISTRY: ghcr.io
REPOSITORY: ${{ github.repository }}
IMAGE_TAG: ${{ steps.short-sha.outputs.sha }}
run: |
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG .
- name: Run Trivy Vulnerability Scanner
uses: aquasecurity/[email protected]
with:
image-ref: "ghcr.io/${{ github.repository }}:${{ steps.short-sha.outputs.sha }}"
format: 'table'
scan-type: 'image'
exit-code: '1'
ignore-unfixed: true
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'
- name: Push docker image to Registry
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
env:
REGISTRY: ghcr.io
REPOSITORY: ${{ github.repository }}
IMAGE_TAG: ${{ steps.short-sha.outputs.sha }}
- name: Login to AWS
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
shell: bash
run: aws eks update-kubeconfig --region us-east-1 --name development
- uses: actions-hub/kubectl@master
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
with:
args: set image deployment/tech-challenge tech-challenge-container=ghcr.io/${{ github.repository }}:${{ steps.short-sha.outputs.sha }}