Skip to content

Commit

Permalink
Merge pull request #8 from shenxianpeng/support-docker-image
Browse files Browse the repository at this point in the history
feat: support docker image
  • Loading branch information
shenxianpeng authored Nov 21, 2024
2 parents 5e20a0b + fdcedb1 commit a11a527
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ on:
jobs:
pre-commit:
uses: shenxianpeng/.github/.github/workflows/pre-commit.yml@main
with:
commands: |
wget -O hadolint https://github.com/hadolint/hadolint/releases/latest/download/hadolint-Linux-x86_64 \
&& chmod +x hadolint \
&& mv hadolint /usr/local/bin/
30 changes: 30 additions & 0 deletions .github/workflows/publish-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Publish Image

on:
push:
paths:
- 'Dockerfile'
workflow_dispatch:
inputs:
tag:
description: 'Which tag want to build'
default: ''
required: false

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build to check Dockerfile
if: github.event.inputs.tag == ''
run: make image
- name: Build and publish docker image
if: github.event.inputs.tag != ''
run: |
echo "tag = ${{ github.event.inputs.tag }}"
make image TAG=${{ github.event.inputs.tag }}
echo $CR_PAT | docker login ghcr.io -u shenxianpeng --password-stdin
make publish-image TAG=${{ github.event.inputs.tag }}
env:
CR_PAT: ${{ secrets.CR_PAT }}
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,14 @@ repos:
rev: v2.3.0
hooks:
- id: codespell
- repo: https://github.com/hadolint/hadolint
rev: v2.12.0
hooks:
- id: hadolint
args:
[
--ignore,DL3008,
--ignore,DL3013,
--ignore,DL3042,
--ignore,SC1091,
]
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM python:3.13-slim

ARG VERSION

# Install git and clean up unnecessary files to reduce image size
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN if [ -z "$VERSION" ]; then \
pip3 install git+https://github.com/shenxianpeng/gitstats.git@main; \
else \
pip3 install git+https://github.com/shenxianpeng/gitstats.git@$VERSION; \
fi

USER nobody

ENTRYPOINT [ "gitstats"]

LABEL com.github.actions.name="Git Stats"
LABEL com.github.actions.description="Check commit message formatting, branch naming, commit author, email, and more."
LABEL com.github.actions.icon="code"
LABEL com.github.actions.color="gray-dark"

LABEL repository="https://github.com/shenxianpeng/git"
LABEL maintainer="shenxianpeng <20297606+shenxianpeng@users.noreply.github.com>"
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ RESOURCES=gitstats.css sortable.js *.gif
BINARIES=gitstats
VERSION=$(shell git describe 2>/dev/null || git rev-parse --short HEAD 2>/dev/null || date +%Y-%m-%d)
SEDVERSION=perl -pi -e 's/VERSION = 0/VERSION = "$(VERSION)"/' --
TAG ?= latest

all: help

Expand All @@ -14,6 +15,8 @@ help:
@echo "make install # install to ${PREFIX}"
@echo "make install PREFIX=~ # install to ~"
@echo "make release [VERSION=foo] # make a release tarball"
@echo "make image # make a docker image"
@echo "make publish-image # publish docker image to dockerhub"
@echo

install:
Expand All @@ -28,7 +31,14 @@ release:
@tar --owner=0 --group=0 --transform 's!^!gitstats/!' --transform 's!gitstats.tmp!gitstats!' -zcf gitstats-$(VERSION).tar.gz gitstats.tmp $(RESOURCES) doc/ Makefile
@$(RM) gitstats.tmp

image:
@docker build -t gitstats:$(TAG) .

publish-image: image
@docker tag gitstats:$(TAG) ghcr.io/shenxianpeng/gitstats:$(TAG)
@docker push ghcr.io/shenxianpeng/gitstats:$(TAG)

man:
pod2man --center "User Commands" -r $(VERSION) doc/gitstats.pod > doc/gitstats.1

.PHONY: all help install release
.PHONY: all help install release image publish-image

0 comments on commit a11a527

Please sign in to comment.