What You'll Learn

Big Picture

Create a fork of this repository

(Optional) Check out your Fork

git clone https://github.com/fhb-codelabs/fhb-codelabs.github.io.git
name: builder

on:
  push:
    branches:
      - 'master'

  pull_request:
    branches:
      - 'master'

jobs: 
##################################
#         Build Artefacts        #
##################################
  container_build:
    runs-on: ubuntu-20.04
    strategy:
      matrix:
        component: [ "legs", "arms", "hats", "main" ]
    steps:
    - name: Checkout Code
      uses: actions/checkout@v2
 
    - name: Login to GitHub Container Registry
      if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/release-*' }}
      uses: docker/login-action@v1
      with:
        registry: ghcr.io
        username: ${{ github.repository_owner }}
        password: ${{ secrets.CR_PAT }}
          
    - name: Lint
      uses: golangci/golangci-lint-action@v2
      with:
        version: v1.29
        working-directory: ${{ matrix.component }}
      
    - name: Build
      id: docker_build
      uses: docker/build-push-action@v2
      with:
        build-args: |
        context: ${{ matrix.component }}/.
        push: false
        file: ${{ matrix.component }}/docker/Dockerfile
        platforms: linux/amd64
        tags: |
           ghcr.io/${{ github.repository_owner }}/podtato-${{ matrix.component }}:${{ github.sha }}

There's an issue

Linting Issue

First success

    - name: Run Trivy vulnerability scanner
      uses: aquasecurity/trivy-action@master
      with:
        image-ref: 'ghcr.io/${{ github.repository_owner }}/podtato-${{ matrix.component }}:${{ github.sha }}'
        format: 'table'
        exit-code: '1'
        ignore-unfixed: 'true'
        vuln-type: 'os,library'
        severity: 'CRITICAL,HIGH'

Another Issue

Successful Build

Start a VM in AWS

Create a security group for SSH

aws ec2 create-security-group --group-name ssh-in --description "SSH Traffic to Instances"
aws ec2 authorize-security-group-ingress \
    --group-name ssh-in \
    --protocol tcp \
    --cidr 0.0.0.0/0 \
    --port 22

Create an Instance

aws ec2 run-instances --image-id ami-087c17d1fe0178315 --instance-type t2.micro --tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=temporary-instance}]" --key-name vockey --security-groups "ssh-in" --output table

Connect to this instance via SSH

INSTANCE_HOSTNAME=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=temporary-instance" --query "Reservations[].Instances[].PublicDnsName" --out text | xargs)
echo "ssh -i ~/.ssh/labsuser.pem ec2-user@${INSTANCE_HOSTNAME}"
ssh -i ~/.ssh/labsuser.pem ec2-user@${INSTANCE_HOSTNAME}

Download cosign

wget https://github.com/sigstore/cosign/releases/download/v1.2.1/cosign-linux-amd64
chmod a+x cosign-linux-amd64

Generate your key pair

./cosign-linux-amd64 generate-key-pair

Enter password for private key: 
Enter password for private key again: 

Add the passphrase to GitHub

    - uses: sigstore/cosign-installer@main
      with:
        cosign-release: 'v1.0.0'
    - name: Build
      id: docker_build_push
      uses: docker/build-push-action@v2
      with:
        build-args: |
        context: ${{ matrix.component }}/.
        push: ${{ github.ref == 'refs/heads/master' }}
        file: ${{ matrix.component }}/docker/Dockerfile
        platforms: linux/amd64
        tags: |
          ghcr.io/${{ github.repository_owner }}/podtato-${{ matrix.component }}:${{ github.sha }}
    - name: Sign Container
      if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/release-*' }}
      env:
        COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
      run: cosign sign -key .github/workflows/cosign.key -a GIT_HASH=${{ env.GIT_SHA }} ghcr.io/${{ github.repository_owner }}/podtato-${{ matrix.component }}:${{ github.sha }}
./cosign-linux-amd64 verify -key cosign.pub ghcr.io/<repo>/podtato-main:<your hash>

Verification for ghcr.io/thschue/podtato-main:bdce48dc9c64a1b42fa1ce15474a82a832471773 --
The following checks were performed on each of these signatures:
  - The cosign claims were validated
  - The signatures were verified against the specified public key
  - Any certificates were verified against the Fulcio roots.

[{"critical":{"identity":{"docker-reference":"ghcr.io/<repo>/podtato-main"},"image":{"docker-manifest-digest":"sha256:eb7e3da2cdbcea455fdbfb189e14bb1bde0574de745d9517b5e8feff77302c75"},"type":"cosign container image signature"},"optional":{"GIT_HASH":""}}]