use image from github #15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Publish Docker Image | |
on: | |
push: | |
branches: | |
- main | |
- master | |
pull_request: | |
branches: | |
- main | |
- master | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.22' | |
- name: Cache Go modules | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/go/pkg/mod | |
~/go/bin | |
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-go- | |
- name: Install pcap | |
run: sudo apt-get update && sudo apt-get install libpcap-dev -y | |
- name: Install dependencies | |
run: go mod download | |
- name: Build the Go application amd64 | |
run: GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -X main.Version=${GITHUB_REF_NAME} -X main.BuildDate=$(date --iso-8601=seconds) -X main.Commit=$CI_COMMIT_SHA -X main.BuildBy=$GITHUB_ACTOR" -o k22r ./ | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.CR_PAT }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
visibility: public | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ghcr.io/${{ github.repository_owner }}/k22r:latest | |