From 31c399caa2a4153d1301f8d58d7488faa2382a44 Mon Sep 17 00:00:00 2001 From: rlardy-ulule Date: Tue, 17 Oct 2023 14:44:39 +0200 Subject: [PATCH] feat: added workflow and modified dockerfile --- .github/workflows/geoipfix.yml | 47 ++++++++++++++++++++++++++++++++++ Dockerfile | 33 ++++++++++++++++-------- 2 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/geoipfix.yml diff --git a/.github/workflows/geoipfix.yml b/.github/workflows/geoipfix.yml new file mode 100644 index 0000000..bbd2509 --- /dev/null +++ b/.github/workflows/geoipfix.yml @@ -0,0 +1,47 @@ +name: Ulule-geoipfix + +on: + push: + paths-ignore: + - '.github/**' + branches-ignore: + - main + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + + +jobs: + build: + timeout-minutes: 30 + runs-on: [self-hosted, linux, x64] + + steps: + - name: Checking out repository + uses: actions/checkout@v3 + + - name: Login to GCR + uses: docker/login-action@v2 + with: + registry: ${{ vars.REGISTRY }} + username: _json_key + password: ${{ secrets.GCR_JSON_KEY }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Removing slashes from branch name when not tag or dev branch + id: git_tag + run: | + echo "GIT_TAG=${GIT_TAG//\//-}" >> "$GITHUB_OUTPUT" + env: + GIT_TAG: ${{ github.ref_name }} + + - name: Build app and push + uses: docker/build-push-action@v4 + with: + context: . + file: Dockerfile + push: true + tags: ${{ vars.REGISTRY }}/ulule-geoipfix:${{ github.sha }},${{ vars.REGISTRY }}/ulule-geoipfix:${{ steps.git_tag.outputs.GIT_TAG }} + cache-from: type=registry,ref=${{ vars.REGISTRY }}/ulule-geoipfix:cache + cache-to: type=registry,ref=${{ vars.REGISTRY }}/ulule-geoipfix:cache,mode=max \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 39d6923..55ec2c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,27 @@ -FROM debian:stretch-slim +FROM golang:1.21-alpine AS geoipfix-builder -RUN apt-get update \ - && apt-get install -y wget +ARG GIT_COMMIT +ARG GIT_BRANCH -RUN mkdir -p /usr/share/geoip \ - && wget -O /tmp/GeoLite2-City.tar.gz http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz \ - && tar xf /tmp/GeoLite2-City.tar.gz -C /usr/share/geoip --strip 1 \ - && gzip /usr/share/geoip/GeoLite2-City.mmdb \ - && ls -al /usr/share/geoip/ +WORKDIR /app -ADD bin/geoipfix /geoipfix +COPY . . -CMD ["/geoipfix"] +RUN --mount=type=cache,target=/root/.cache/go-build \ + CGO_ENABLED=0 go build -ldflags "\ + -X 'github.com/ulule/geoipfix.Branch=${GIT_BRANCH})' \ + -X 'github.com/ulule/geoipfix.Revision=${GIT_COMMIT}' \ + -X 'github.com/ulule/geoipfix.Compiler=$(go version)'" -a -installsuffix cgo -o /geoipfix ./cmd/main.go + +#FROM alpine +FROM scratch + +# RUN addgroup -S chouette && \ +# adduser -S chouette -G chouette && \ +# apk add --no-cache ca-certificates + +# USER chouette:chouette + +COPY --from=geoipfix-builder /geoipfix /geoipfix + +ENTRYPOINT ["/geoipfix"] \ No newline at end of file