Skip to content

Commit

Permalink
Merge pull request #32 from funnyzak:gitsync
Browse files Browse the repository at this point in the history
Add Docker support for git-sync
  • Loading branch information
funnyzak authored Dec 25, 2024
2 parents 1372053 + 97640ae commit 87fb3b9
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 125 deletions.
27 changes: 13 additions & 14 deletions .github/workflows/dispatch-choice.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ on:
- nginx
- openjdk
- nezha-dashboard
- git-sync
- cron
- vcards
- vcards-pro
- certimate
- mysql-dump
- dify2openai
Expand Down Expand Up @@ -76,19 +76,7 @@ jobs:
build_args: ${{ github.event.inputs.build_args }}
build_platforms: ${{ github.event.inputs.build_platforms || 'linux/amd64,linux/arm64' }}
secrets: inherit

vcards_pro_release:
if: ${{ github.event.inputs.choice_service == 'vcards-pro' }}
uses: ./.github/workflows/release.yml
with:
build_context: './Docker/vcards'
docker_image_name: vcards-pro
docker_file_name: 'Dockerfile.pro'
docker_tags: ${{ github.event.inputs.docker_tags }}
build_args: ${{ github.event.inputs.build_args }}
build_platforms: ${{ github.event.inputs.build_platforms || 'linux/amd64,linux/arm64' }}
secrets: inherit


env_mock_data_release:
if: ${{ github.event.inputs.choice_service == 'env-mock-data' }}
uses: ./.github/workflows/release.yml
Expand All @@ -111,6 +99,17 @@ jobs:
build_platforms: ${{ github.event.inputs.build_platforms || 'linux/amd64,linux/arm64,linux/arm64/v8' }}
secrets: inherit

git_sync_release:
if: ${{ github.event.inputs.choice_service == 'git-sync' }}
uses: ./.github/workflows/release.yml
with:
build_context: './Docker/git-sync'
docker_image_name: git-sync
docker_tags: ${{ github.event.inputs.docker_tags }}
build_args: ${{ github.event.inputs.build_args }}
build_platforms: ${{ github.event.inputs.build_platforms || 'linux/amd64,linux/arm64,linux/arm/v7' }}
secrets: inherit

openjdk_release:
if: ${{ github.event.inputs.choice_service == 'openjdk' }}
uses: ./.github/workflows/release.yml
Expand Down
23 changes: 12 additions & 11 deletions .github/workflows/schedule-watch-offical.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,22 @@ jobs:
uses: ./.github/workflows/check-offical-release.yml
with:
image_name: one-api
build_context: './Docker/one-api'
get_official_version_command: 'curl -s https://api.github.com/repos/songquanpeng/one-api/releases/latest | jq -r ".tag_name // \"no-tags\""'
is_latest_tag: true
build_platforms: 'linux/amd64'
secrets: inherit

watch_git_sync_release:
uses: ./.github/workflows/check-offical-release.yml
with:
image_name: git-sync
build_context: './Docker/git-sync'
get_official_version_command: 'curl -s https://api.github.com/repos/AkashRajpurohit/git-sync/releases/latest | jq -r ".tag_name // \"no-tags\""'
is_latest_tag: true
build_platforms: 'linux/amd64,linux/arm64,linux/arm/v7'
secrets: inherit

watch_nezha_dashboard_release:
uses: ./.github/workflows/check-offical-release.yml
with:
Expand All @@ -51,17 +62,7 @@ jobs:
uses: ./.github/workflows/check-offical-release.yml
with:
image_name: vcards
get_official_version_command: 'curl -s https://api.github.com/repos/metowolf/vCards/releases/latest | jq -r ".tag_name // \"no-tags\""'
is_latest_tag: true
build_platforms: 'linux/amd64,linux/arm64'
secrets: inherit

watch_vcards_pro_release:
uses: ./.github/workflows/check-offical-release.yml
with:
build_context: './Docker/vcards'
image_name: vcards-pro
get_official_version_command: 'curl -s https://api.github.com/repos/funnyzak/vCards/tags | jq -r ".[0].name // \"no-tags\""'
get_official_version_command: 'curl -s https://api.github.com/repos/funnyzak/vCards/releases/latest | jq -r ".tag_name // \"no-tags\""'
is_latest_tag: true
build_platforms: 'linux/amd64,linux/arm64'
secrets: inherit
Expand Down
2 changes: 1 addition & 1 deletion Docker/abracadabra-web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ services:
**After Startup**:
![Abracadabra_demo](https://cdn.jsdelivr.net/gh/funnyzak/docker-release@main/Docker/abracadabra-web/abracadabra-demo.png)
![Abracadabra_demo](https://github.com/user-attachments/assets/5f9e5806-6372-49ce-9088-cc60bb47ed65)
Binary file removed Docker/abracadabra-web/abracadabra-demo.png
Binary file not shown.
50 changes: 50 additions & 0 deletions Docker/git-sync/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
FROM golang:1.23.4-alpine AS builder

WORKDIR /go/src/app

RUN apk update && \
apk add upx ca-certificates tzdata git

ARG VERSION
ARG BUILD_DATE
ARG VCS_REF

ENV GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux

RUN git clone https://github.com/AkashRajpurohit/git-sync.git . \
&& git checkout ${VERSION} || git checkout $(git remote show origin | awk '/HEAD branch/ {print $NF}') \
&& echo ${VERSION:-$(git rev-parse --short=12 HEAD)}-$(git log -1 --format=%cd --date=format:'%y%m%d') > VERSION

RUN go mod download \
&& go mod tidy

RUN go build -a -installsuffix cgo -ldflags="-w -s -X github.com/AkashRajpurohit/git-sync/pkg/version.Version=${VERSION} -X github.com/AkashRajpurohit/git-sync/pkg/version.Build=${BUILD_DATE}" -o git-sync . \
&& upx -q git-sync

FROM alpine:latest
WORKDIR /opt/go

LABEL org.label-schema.name="git-sync" \
org.label-schema.description="A simple tool to backup and sync your git repositories." \
org.label-schema.version="${VERSION}" \
org.label-schema.build-date="${BUILD_DATE}" \
org.label-schema.vcs-ref="${VCS_REF}" \
org.label-schema.vendor="Leon<silenceace@gmail.com>" \
org.label-schema.url="https://github.com/funnyzak/docker-release"

RUN apk update && \
apk add git su-exec

RUN mkdir -p /git-sync /backups

COPY --from=builder /go/src/app/git-sync /opt/go/git-sync
COPY --from=builder /go/src/app/VERSION /opt/go/VERSION
COPY --from=builder /go/src/app/entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh", "/opt/go/git-sync"]
CMD ["--config", "/git-sync/config.yaml", "--backup-dir", "/backups"]

88 changes: 88 additions & 0 deletions Docker/git-sync/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# git-sync

[![Docker Tags](https://img.shields.io/docker/v/funnyzak/git-sync?sort=semver&style=flat-square)](https://hub.docker.com/r/funnyzak/git-sync/)
[![Image Size](https://img.shields.io/docker/image-size/funnyzak/git-sync)](https://hub.docker.com/r/funnyzak/git-sync/)
[![Docker Stars](https://img.shields.io/docker/stars/funnyzak/git-sync.svg?style=flat-square)](https://hub.docker.com/r/funnyzak/git-sync/)
[![Docker Pulls](https://img.shields.io/docker/pulls/funnyzak/git-sync.svg?style=flat-square)](https://hub.docker.com/r/funnyzak/git-sync/)

`git-sync` is a CLI tool designed to help you back up your Git repositories. This tool ensures you have a local copy of your repositories, safeguarding against potential issues such as account bans or data loss.
. This image supports `linux/amd64`,`linux/arm/v7`, `linux/arm64`.

You can pull the images using the following commands:

```bash
docker pull funnyzak/git-sync:latest
# GHCR
docker pull ghcr.io/funnyzak/git-sync:latest
# Aliyun
docker pull registry.cn-beijing.aliyuncs.com/funnyzak/git-sync:latest
```

---

## Usage Example

### Docker run

```bash
docker run \
--name=git-sync \
-e PUID=1000 \
-e PGID=1000 \
-v ./git-sync/config.yaml:/git-sync/config.yaml \
-v ./git-backups:/backups \
funnyzak/git-sync:latest
```

### Docker Compose

```yaml
version: '3'
services:
git-sync:
image: funnyzak/git-sync:latest
container_name: git-sync
environment:
- PUID=1000
- PGID=1000
volumes:
- ./git-sync/config.yaml:/git-sync/config.yaml
- ./git-backups:/backups
```
### Configuration
Here is an example of a `config.yaml` file:

```yaml
# Git Sync Configuration
# Repository settings
include_forks: false # Include forked repositories
include_wiki: true # Include wiki's
include_repos: [] # Include specific repositories
exclude_repos: [] # Exclude specific repositories
include_orgs: [] # Include repositories from specific organizations
exclude_orgs: [] # Exclude repositories from specific organizations
raw_git_urls: [] # Raw valid git URLs
# Authentication
username: <username>
tokens: [<token 1>]
# Server settings
backup_dir: /path/to/backup
clone_type: bare # Clone type: bare, shallow, mirror or full. Default: bare
cron: 0 0 * * * # run every 24 hours at 00:00
concurrency: 5
retry:
count: 3
delay: 10 # in seconds
platform: github
server:
domain: github.com
protocol: https
```
More information about the configuration can be found [here](https://github.com/AkashRajpurohit/git-sync/wiki/Configuration).

More Examples can be found [here](https://github.com/AkashRajpurohit/git-sync/wiki/Examples).
2 changes: 1 addition & 1 deletion Docker/request-hub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ services:

## Preview

![preview](./request-hub-demo.jpg)
![preview](https://github.com/user-attachments/assets/a4dacbb9-1131-4db9-a5f3-3d477487a070)
Binary file removed Docker/request-hub/request-hub-demo.jpg
Binary file not shown.
9 changes: 5 additions & 4 deletions Docker/vcards/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM node:20-alpine3.19 AS builder

ARG VERSION

WORKDIR /app

RUN apk add --no-cache git

ARG VERSION

WORKDIR /app

RUN git clone https://github.com/metowolf/vCards . \
RUN git clone https://github.com/funnyzak/vCards . \
&& git checkout ${VERSION} || git checkout $(git remote show origin | awk '/HEAD branch/ {print $NF}') \
&& echo ${VERSION:-$(git rev-parse HEAD)} > VERSION

Expand Down Expand Up @@ -68,7 +68,8 @@ RUN apk add --no-cache \

ENV TZ=Asia/Shanghai
ENV DOWNLOAD_DIR="/app/downloads"
ENV REPO_NAME="metowolf/vCards"
ENV REPO_NAME="funnyzak/vCards"
ENV SYNC_ON_STARTUP="true"

COPY --from=builder /app/radicale/ /app/vcards/collection-root/cn/
COPY --from=builder /app/VERSION /app/VERSION
Expand Down
82 changes: 0 additions & 82 deletions Docker/vcards/Dockerfile.pro

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ download_and_sync() {

mkdir -p ${DOWNLOAD_DIR}/vcards/${VERSION}

curl -sSL https://github.com/${REPO_NAME}/releases/download/${VERSION}/archive.zip -o ${DOWNLOAD_DIR}/vcards/archive-${VERSION}.zip
unzip -o ${DOWNLOAD_DIR}/vcards/archive-${VERSION}.zip -d ${DOWNLOAD_DIR}/vcards/${VERSION}
if [ -n "$(find ${DOWNLOAD_DIR}/vcards/${VERSION} -name '*.vcf')" ]; then
rsync -a --update ${DOWNLOAD_DIR}/vcards/${VERSION}/* ${VCARD_DIR_PATH}
echo -e "Sync vCards done, $(find ${VCARD_DIR_PATH} -name '*.vcf' | wc -l) files synced."
curl -sSL https://github.com/${REPO_NAME}/releases/download/${VERSION}/radicale.zip -o ${DOWNLOAD_DIR}/vcards/radicale-${VERSION}.zip
unzip -o ${DOWNLOAD_DIR}/vcards/radicale-${VERSION}.zip -d ${DOWNLOAD_DIR}/vcards/${VERSION}
if [ -n "$(find ${DOWNLOAD_DIR}/vcards/${VERSION}/radicale -name '*.vcf')" ]; then
rsync -a --update --exclude='汇总/' ${DOWNLOAD_DIR}/vcards/${VERSION}/radicale/* ${VCARD_DIR_PATH}
echo -e "Sync vCards done, $(find ${VCARD_DIR_PATH} -type d -name '*cache*' -prune -o -type f -name '*.vcf' -print | wc -l) files synced."
echo $VERSION > /app/VERSION
else
echo -e "${RED}Sync vCards failed, no vcf files found.${NC}"
fi
}

echo -e "${GREEN}Current vCards: $(find ${VCARD_DIR_PATH} -name '*.vcf' | wc -l) files.${NC}"
echo -e "${GREEN}Current vCards: $(find ${VCARD_DIR_PATH} -type d -name '*cache*' -prune -o -type f -name '*.vcf' -print | wc -l) files.${NC}"

echo -e "${GREEN}${REPO_NAME} ${CURRENT_VERSION}, syncing vCards.${NC}"

Expand All @@ -41,7 +42,6 @@ else
else
echo -e "${BLUE}Current version: ${CURRENT_VERSION}, latest version: ${LATEST_VERSION}, downloading and syncing.${NC}"
download_and_sync $LATEST_VERSION
echo $LATEST_VERSION > /app/VERSION
fi
fi

Loading

0 comments on commit 87fb3b9

Please sign in to comment.