workflow updates

add goreleaser.yml
	use goreleaser action to build/publish netmaker/nmctl release assets
streamline Dockerfile
update go-builder to run on push to develop
This commit is contained in:
Matthew R Kasun 2023-02-15 09:29:28 -05:00
parent 380a353f46
commit 3fcbce7ab6
5 changed files with 48 additions and 48 deletions

View file

@ -13,61 +13,32 @@ jobs:
version:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.echo.outputs.tag }}
version: ${{ steps.echo.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
version: ${{ steps.version.outputs.version }}
steps:
- name: Get Version Number
id: version
run: |
if [[ -n "${{ github.event.inputs.version }}" ]]; then
NETMAKER_VERSION=${{ github.event.inputs.version }}
else
NETMAKER_VERSION=$(curl -fsSL https://api.github.com/repos/gravitl/netmaker/tags | grep 'name' | head -1 | cut -d'"' -f4)
fi
echo "NETMAKER_VERSION=${NETMAKER_VERSION}" >> $GITHUB_ENV
echo "NETMAKER_VERSION=${NETMAKER_VERSION}" >> $GITHUB_OUTPUT
# remove everything but digits and . for package (deb, rpm, etc) versions
PACKAGE_VERSION=$(echo ${NETMAKER_VERSION} | tr -cd '[:digit:].')
echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> $GITHUB_ENV
- name: Echo
id: echo
run: |
echo ${{ env.NETMAKER_VERSION }}
echo ${{ env.PACKAGE_VERSION }}
if [[ -z ${{ env.NETMAKER_VERSION }} || -z ${{ env.PACKAGE_VERSION }} ]]
then
exit 1
fi
echo "::set-output name=tag::${{ env.NETMAKER_VERSION }}"
echo "::set-output name=version::${{ env.PACKAGE_VERSION }}"
netmaker:
echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> $GITHUB_OUTPUT
netmaker-nmctl:
runs-on: ubuntu-latest
needs: version
steps:
- name: set variables
run: |
echo ${{ needs.version.outputs.tag }} ${{ needs.version.outputs.version }}
TAG=${{needs.version.outputs.tag}}
VERSION=${{needs.version.outputs.version}}
if [[ -z ${VERSION} || -z ${TAG} ]]; then
exit 1
fi
echo "NETMAKER_VERSION=${TAG}" >> $GITHUB_ENV
echo "PACKAGE_VERSION=${VERSION}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v3
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Build
run: |
env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags="-X 'main.version=${NETMAKER_VERSION}'" -o build/netmaker main.go
- name: Upload netmaker x86 to Release
uses: svenstaro/upload-release-action@v2
- name: GoReleaser
uses: actions/goreleaser-action@v4
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: build/netmaker
tag: ${{ env.NETMAKER_VERSION }}
overwrite: true
prerelease: true
asset_name: netmaker
args: release --clean

View file

@ -2,8 +2,9 @@ name: Build go-builder images
on:
workflow_dispatch:
schedule:
- cron: '00 21 * * SUN'
push:
branches:
- 'develop'
jobs:
go-builder:

View file

@ -48,7 +48,6 @@ jobs:
push: true
tags: ${{ github.repository }}:${{ env.TAG }}, ${{ github.repository }}:latest
build-args: |
version=${{ env.TAG }}
tags=ce
docker-ee:
@ -89,5 +88,4 @@ jobs:
push: true
tags: ${{ github.repository }}:${{ env.TAG }}-ee
build-args: |
version=${{ env.TAG }}
tags=ee

35
.goreleaser.yaml Normal file
View file

@ -0,0 +1,35 @@
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
builds:
- main: ./
id: netmaker
env:
- CGO_ENABLED=1
ldflags:
- -s -w
targets:
- linux_amd64
no_unique_dist_dir: true
binary: '{{ .id }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}'
- main: ./cli
id: nmctl
env:
- CGO_ENABLED=0
ldflags:
- -s -w
targets:
- linux_amd64
- linux_arm64
- darwin_amd64
- darwin_arm64
- freebsd_amd64
- windows_amd64
no_unique_dist_dir: true
binary: '{{ .id }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}'
archives:
- format: binary
name_template: '{{ .id}}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}'
changelog:
skip: true

View file

@ -1,18 +1,13 @@
#first stage - builder
FROM gravitl/go-builder as builder
ARG version
ARG tags
WORKDIR /app
COPY . .
ENV GO111MODULE=auto
RUN apk add git
RUN GOOS=linux CGO_ENABLED=1 go build -ldflags="-s -X 'main.version=${version}'" -tags ${tags} .
RUN GOOS=linux CGO_ENABLED=1 go build -ldflags="-s -w" -tags ${tags} .
# RUN go build -tags=ee . -o netmaker main.go
FROM alpine:3.16.2
# add a c lib
RUN apk add gcompat iptables wireguard-tools
# set the working directory
WORKDIR /root/
RUN mkdir -p /etc/netclient/config