Skip to content

Commit

Permalink
refactor python to golang
Browse files Browse the repository at this point in the history
  • Loading branch information
sholdee committed Jul 8, 2024
1 parent fee49a1 commit 02c5da2
Show file tree
Hide file tree
Showing 9 changed files with 592 additions and 306 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Dockerfile
LICENSE
README.md
assets/
.github/
.git/
16 changes: 8 additions & 8 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Build and Push Docker Image
name: Build and Push Go Docker Image

on:
push:
branches:
- master
- golang
tags:
- 'v*'
pull_request:
branches:
- master
- golang

permissions:
contents: read
Expand Down Expand Up @@ -37,15 +37,15 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
tags: sholdee/adguardexporter:test-${{ github.sha }}
tags: sholdee/adguardexporter:golang-test-${{ github.sha }}
platforms: linux/amd64,linux/arm64
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

push:
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
if: github.ref == 'refs/heads/golang' || startsWith(github.ref, 'refs/tags/')

steps:
- name: Checkout repository
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
sholdee/adguardexporter
ghcr.io/${{ github.repository_owner }}/adguard-exporter
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
type=raw,value=golang-latest,enable=${{ github.ref == 'refs/heads/golang' }}
type=ref,event=branch
type=ref,event=tag
type=semver,pattern={{version}}
Expand All @@ -102,5 +102,5 @@ jobs:

- name: Verify Docker manifest
run: |
docker buildx imagetools inspect sholdee/adguardexporter:latest
docker buildx imagetools inspect ghcr.io/${{ github.repository }}:latest
docker buildx imagetools inspect sholdee/adguardexporter:golang-latest
docker buildx imagetools inspect ghcr.io/${{ github.repository }}:golang-latest
3 changes: 0 additions & 3 deletions .gitignore

This file was deleted.

29 changes: 18 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
FROM python:3-alpine
FROM golang:1.22-alpine3.20 AS builder

WORKDIR /app

# Install build dependencies
RUN apk add --no-cache --virtual .build-deps gcc musl-dev
# Copy go mod and sum files
COPY go.mod go.sum ./

# Copy and install requirements
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Download all dependencies
RUN go mod download

# Remove build dependencies
RUN apk del .build-deps
# Copy the source code
COPY *.go ./

# Copy the script
COPY adguard_exporter.py .
# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-s -w" -o adguard_exporter .

# Create a minimal Alpine image
FROM alpine:3.20

WORKDIR /app

# Copy the binary from the builder stage
COPY --from=builder /app/adguard_exporter .

# Expose the metrics port
EXPOSE 8000
Expand All @@ -24,4 +31,4 @@ ENV METRICS_PORT=8000
ENV LOG_LEVEL=INFO

# Run the exporter
CMD ["python", "./adguard_exporter.py"]
CMD ["./adguard_exporter"]
Loading

0 comments on commit 02c5da2

Please sign in to comment.