From 62b22642986562a7a459cd1f2788e13b05e5ce5b Mon Sep 17 00:00:00 2001 From: Chuck Bear Date: Fri, 10 May 2024 07:59:40 -0400 Subject: [PATCH] feat(build): add Dockerfile and github action for it --- .github/workflows/docker.yml | 52 ++++++++++++++++++++++++++++++++++++ Dockerfile | 15 +++++++++++ 2 files changed, 67 insertions(+) create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..c8a37ef --- /dev/null +++ b/.github/workflows/docker.yml @@ -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 }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ca29863 --- /dev/null +++ b/Dockerfile @@ -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 +