Skip to content

Commit

Permalink
feat: Added GitHub Actions CI/CD + Updated Docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Dec 29, 2020
1 parent 59e3b89 commit bea8976
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 16 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/workflow.yml
@@ -0,0 +1,69 @@
# GitHub Actions Workflow
# To trigger the release pipeline create a new GitHub Release in the repository and set it as a pre-release.
# This workflow requires a secret called CR_PAT which is a GitHub Personal Access Token with scope for GitHub Packages Read/Write

name: CICD
on: [push, pull_request]

jobs:
# Note: GitHub Actions does not yet support IPv6 which is required to run the E2E tests so they have been disabled.
# Note: Repository must be configured with secrets NDDNS_TEST_ZONE and NDDNS_TEST_ACCESS_TOKEN for propper function of the E2E test.
# test:
# strategy:
# matrix:
# os: [ubuntu-latest, macos-latest, windows-latest]
# runs-on: ${{ matrix.os }}
# steps:
# - uses: actions/checkout@v2
# - name: Setup Go
# uses: actions/setup-go@v2
# - name: Go Installation Information
# run: go version
# - name: Run E2E Tests
# run: go test ./cmd
# env:
# NDDNS_DISABLE_ANALYTICS: true
# NDDNS_TEST_ZONE: ${{ secrets.NDDNS_TEST_ZONE }}
# NDDNS_TEST_ACCESS_TOKEN: ${{ secrets.NDDNS_TEST_ACCESS_TOKEN }}
build-release:
runs-on: ubuntu-latest
# needs: test
steps:
- uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
- name: Which Go Version
run: go version
- name: Build Binaries For All Targets
run: |
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.Version=${GITHUB_REF#refs/tags/}" -o nddns_Linux ./cmd
GOOS=linux GOARCH=arm64 go build -ldflags "-X main.Version=${GITHUB_REF#refs/tags/}" -o nddns_Linux_Arm64 ./cmd
GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.Version=${GITHUB_REF#refs/tags/}" -o nddns_macOS ./cmd # TODO: Move this to exclusive Apple Silicon support after the transition is complete
GOOS=windows GOARCH=amd64 go build -ldflags "-X main.Version=${GITHUB_REF#refs/tags/}" -o nddns_Windows ./cmd
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/v')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
nddns_Linux
nddns_Linux_Arm64
nddns_macOS
nddns_Windows
docker-release:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v2
- name: Authenticate with GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: oscartbeaumont
password: ${{ secrets.CR_PAT }}
- name: Build
run: docker build --build-arg VERSION="${GITHUB_REF#refs/tags/}" -t "ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_REF#refs/tags/}" .
- name: Push
run: docker push "ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_REF#refs/tags/}"
23 changes: 11 additions & 12 deletions Dockerfile
@@ -1,23 +1,22 @@
FROM golang:alpine AS builder

RUN adduser -D -g '' app
ARG VERSION

RUN adduser -D -g '' nddns_usr

RUN apk update && \
apk add --no-cache git ca-certificates && \
update-ca-certificates

RUN wget https://raw.githubusercontent.com/golang/dep/master/install.sh && \
sh install.sh

WORKDIR $GOPATH/src/github.com/oscartbeaumont/netlify-dynamic-dns
COPY Gopkg.toml Gopkg.lock ./
RUN dep ensure --vendor-only
COPY . ./
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o ./netlify-ddns ./cmd
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -ldflags "-X main.Version=${VERSION}" -o ./nddns ./cmd

FROM scratch
LABEL org.opencontainers.image.title Netlify Dynamic DNS
LABEL org.opencontainers.image.source https://github.com/oscartbeaumont/netlify-dynamic-dns
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd
USER app
COPY --from=builder /go/src/github.com/oscartbeaumont/netlify-dynamic-dns/netlify-ddns ./netlify-ddns
ENTRYPOINT ["./netlify-ddns"]
USER nddns_usr
COPY --from=builder /src/nddns /
ENTRYPOINT ["/nddns"]
2 changes: 1 addition & 1 deletion cmd/args.go
@@ -1,7 +1,7 @@
package main

// Version contains the builds version. It is injected at build time
const Version = "v0.0.0-dev"
var Version = "v0.0.0-dev"

// Arguments stores the configuration which is determined from the command line arguments or environment varibles
type Arguments struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Expand Up @@ -57,7 +57,7 @@ func main() {
s.Stop()

if err != nil {
log.Println(Red + "Error: Error Updating DNS Record." + err.Error() + Reset)
log.Println(Red + "Error: Error Updating DNS Record " + err.Error() + Reset)
}
if args.Interval == 0 {
log.Println(Green + "DNS records updated successfully." + Reset + "")
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Expand Up @@ -10,3 +10,5 @@ require (
github.com/miekg/dns v1.1.35
github.com/netlify/open-api v1.1.0
)

replace github.com/janeczku/go-spinner => github.com/dmolesUC/go-spinner v0.0.0-20190903171623-0c332afb0926
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -60,6 +60,8 @@ github.com/deadcheat/gonch v0.0.0-20180528124129-c2ff7a019863/go.mod h1:/5mH3gAu
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dmolesUC/go-spinner v0.0.0-20190903171623-0c332afb0926 h1:UV3snoSWHmkNeyGTO6WO9mjp033hWtabYv9wVUmmXgo=
github.com/dmolesUC/go-spinner v0.0.0-20190903171623-0c332afb0926/go.mod h1:WcFEJ3AsmcR5cApVBZyUWkRdu0IoDRakYe1wJmMm8LQ=
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down Expand Up @@ -197,8 +199,6 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/janeczku/go-spinner v0.0.0-20150530144529-cf8ef1d64394 h1:X8X7KPD2Gfk34zCn4C47e5UxUK72Oz8sBpe6aiN1gZE=
github.com/janeczku/go-spinner v0.0.0-20150530144529-cf8ef1d64394/go.mod h1:Z8lFST9wVOwMDDBpMpCCnpk93WKTb+UWT/4TTUxWZzA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
Expand Down

0 comments on commit bea8976

Please sign in to comment.