Skip to content

Commit

Permalink
Build docker hub images. Set version during build. Add deploy examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
lovelaze committed Aug 27, 2024
1 parent 8e4e428 commit 37526eb
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 12 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Extract tag
id: extract_tag
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
Expand All @@ -39,8 +46,12 @@ jobs:
tags: |
ghcr.io/lovelaze/nebula-sync:latest
ghcr.io/lovelaze/nebula-sync:${{ env.TAG }}
docker.io/lovelaze/nebula-sync:latest
docker.io/lovelaze/nebula-sync:${{ env.TAG }}
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
provenance: false
build-args: |
VERSION=${{ env.TAG }}
release:
needs: docker
Expand Down
3 changes: 1 addition & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ builds:
- arm64

goarm:
- 5
- 6
- 7

Expand All @@ -45,7 +44,7 @@ archives:
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
version_template: "{{ .Tag }}-next"

changelog:
sort: asc
Expand Down
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ COPY . .
RUN go mod download
RUN go mod verify

ARG VERSION=dev

ENV GO111MODULE=on
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOFLAGS="-a -ldflags=-w -ldflags=-s -trimpath -o=nebula-sync"
ENV GOFLAGS="-a -trimpath -ldflags=-w -ldflags=-s -ldflags=-X=github.com/lovelaze/nebula-sync/version.Version=${VERSION} -o=nebula-sync"

RUN go build . && \
upx -q nebula-sync

FROM scratch

COPY --from=golang /usr/share/zoneinfo/ /usr/share/zoneinfo/
COPY --from=golang /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=golang /app/nebula-sync /usr/local/bin/
COPY --link --from=golang /usr/share/zoneinfo/ /usr/share/zoneinfo/
COPY --link --from=golang /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --link --from=golang /app/nebula-sync /usr/local/bin/

USER 1001

Expand Down
4 changes: 4 additions & 0 deletions examples/.env_full
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PRIMARY=http://ph1.example.com|password
REPLICAS=http://ph2.example.com|password
FULL_SYNC=true
CRON=0 * * * *
21 changes: 21 additions & 0 deletions examples/.env_manual
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
PRIMARY=http://ph1.example.com|password
REPLICAS=http://ph2.example.com|password
FULL_SYNC=false
CRON=0 * * * *

SYNC_CONFIG_DNS=true
SYNC_CONFIG_DHCP=true
SYNC_CONFIG_NTP=true
SYNC_CONFIG_RESOLVER=true
SYNC_CONFIG_DATABASE=true
SYNC_CONFIG_MISC=true
SYNC_CONFIG_DEBUG=true

SYNC_GRAVITY_DHCP_LEASES=true
SYNC_GRAVITY_GROUP=true
SYNC_GRAVITY_AD_LIST=true
SYNC_GRAVITY_AD_LIST_BY_GROUP=true
SYNC_GRAVITY_DOMAIN_LIST=true
SYNC_GRAVITY_DOMAIN_LIST_BY_GROUP=true
SYNC_GRAVITY_CLIENT=true
SYNC_GRAVITY_CLIENT_BY_GROUP=true
10 changes: 10 additions & 0 deletions examples/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
services:
nebula-sync:
image: ghcr.io/lovelaze/nebula-sync:latest
container_name: nebula-sync
environment:
- PRIMARY=http://ph1.example.com|password
- REPLICAS=http://ph2.example.com|password,http://ph3.example.com|password
- FULL_SYNC=true
- CRON=0 * * * *
6 changes: 1 addition & 5 deletions internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Init() (*Service, error) {
}

func (service *Service) Run() error {
log.Info().Msgf("Starting nebula-sync v%s", version.Version)
log.Info().Msgf("Starting nebula-sync %s", version.Version)
log.Debug().Str("config", service.conf.String()).Msgf("Settings")

if service.conf.Cron == nil {
Expand Down Expand Up @@ -73,7 +73,3 @@ func (service *Service) startCron(cmd func()) error {
cron.Run()
return nil
}

func (service *Service) Target() sync.Target {
return service.target
}
4 changes: 3 additions & 1 deletion version/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package version

const Version = "0.2.2"
var (
Version = "dev"
)

0 comments on commit 37526eb

Please sign in to comment.