Skip to content

Commit

Permalink
feat(build): add Dockerfile and github action for it
Browse files Browse the repository at this point in the history
  • Loading branch information
chuck-bear committed May 10, 2024
1 parent 4fe1d5b commit 62b2264
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Docker Build

on:
push:
branches:
- '*'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
GIT_TOKEN: ${{ secrets.GH_TOKEN }}

jobs:
build-and-push:
runs-on:
labels: ubuntu-latest-large
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
file: Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
TAG=${{ github.ref_name }}
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM golang:1.21 as builder

WORKDIR /app

COPY . .

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o attacknetd ./cmd/attacknet

# Use a Docker multi-stage build to create a lean production image.
# Start with a smaller image
FROM alpine:latest

# Copy the binary and any other dependencies from the builder stage
COPY --from=builder /app/attacknetd /usr/local/bin/attacknetd

0 comments on commit 62b2264

Please sign in to comment.