Skip to content

Add GitHub Actions workflow for building, testing, and scanning Go anโ€ฆ #2

Add GitHub Actions workflow for building, testing, and scanning Go anโ€ฆ

Add GitHub Actions workflow for building, testing, and scanning Go anโ€ฆ #2

Workflow file for this run

name: ๐Ÿณ Build and Push Docker Images
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
permissions:
contents: read
packages: write
jobs:
build-backend:
name: ๐Ÿ› ๏ธ Build and Push
runs-on: ubuntu-latest
steps:
- name: ๐Ÿš€ Checkout Code
uses: actions/checkout@v4
# Get version from version.yaml
- name: ๐Ÿ“ Get version
run: |
echo "VERSION=$(cat version.yaml | sed -n 's/version: //p')" >> $GITHUB_ENV
echo $VERSION
# Set build tags based on branch
- name: ๐Ÿ—๏ธ Set Build tags
run: |
if [ $GITHUB_REF = 'refs/heads/main' ]; then
echo "IMAGE_TAGS=$VERSION" >> $GITHUB_ENV
else
echo "IMAGE_TAGS=rc-$VERSION-$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
fi
- name: ๐Ÿ› ๏ธ Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Login to GitHub Container Registry
- name: ๐Ÿ” Login to GitHub Container Registry
uses: docker/#-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.TOKEN }}
# Login to Docker Hub
- name: ๐Ÿ” Login to Docker Hub
if: github.ref == 'refs/heads/main'
uses: docker/#-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: ๐Ÿ“ฆ Build and Push Image to GHCR (PR)
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ghcr.io/kek-sec/goshort:${{ env.IMAGE_TAGS }}
annotations: |
org.opencontainers.image.description=goshort, url shortener
build-args: |
VERSION=${{ env.VERSION }}
labels: |
org.opencontainers.image.source=https://github.com/kek-sec/goshort
cache-from: type=registry,ref=ghcr.io/kek-sec/goshort:latest
cache-to: type=registry,ref=ghcr.io/kek-sec/goshort:latest
- name: ๐Ÿ“ฆ Build and Push Image to GHCR and Docker Hub (Main)
if: github.ref == 'refs/heads/main'
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: |
ghcr.io/kek-sec/goshort:${{ env.IMAGE_TAGS }}
petrakisg/goshort:${{ env.IMAGE_TAGS }}
annotations: |
org.opencontainers.image.description=goshort, a secure one-time secret sharing service
build-args: |
VERSION=${{ env.VERSION }}
labels: |
org.opencontainers.image.source=https://github.com/kek-sec/goshort
cache-from: type=registry,ref=ghcr.io/kek-sec/goshort:latest
cache-to: type=registry,ref=ghcr.io/kek-sec/goshort:latest