Skip to content

Commit

Permalink
wip, migrate all scripts to new build pattern (Makefile + multiple GH…
Browse files Browse the repository at this point in the history
… agents).
  • Loading branch information
AnalogJ committed Jul 7, 2022
1 parent 316ce85 commit 4a16ca0
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 151 deletions.
83 changes: 0 additions & 83 deletions .github/workflows/release-freebsd.yaml

This file was deleted.

8 changes: 2 additions & 6 deletions .github/workflows/release-frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ jobs:
run: "cd webapp/frontend && ./git.version.sh"
- name: Build Frontend
run: |
cd webapp/frontend
npm install -g @angular/cli@9.1.4
npm install
mkdir -p dist
npm run build:prod -- --output-path=dist
make binary-frontend
tar -czf scrutiny-web-frontend.tar.gz dist
- name: Upload Frontend Asset
id: upload-release-asset3
Expand All @@ -32,6 +28,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.SCRUTINY_GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: './webapp/frontend/scrutiny-web-frontend.tar.gz'
asset_path: './scrutiny-web-frontend.tar.gz'
asset_name: scrutiny-web-frontend.tar.gz
asset_content_type: application/gzip
121 changes: 87 additions & 34 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ on:
default: 'webapp/backend/pkg/version/version.go'

jobs:
build:
name: Build
release:
name: Create Release Commit
runs-on: ubuntu-latest
container: techknowlogick/xgo:go-1.17.x
container: ghcr.io/packagrio/packagr:latest-golang
# Service containers to run with `build` (Required for end-to-end testing)
services:
influxdb:
Expand All @@ -31,8 +31,7 @@ jobs:
ports:
- 8086:8086
env:
PROJECT_PATH: /go/src/github.com/analogj/scrutiny
CGO_ENABLED: 1
STATIC: true
steps:
- name: Git
run: |
Expand All @@ -53,34 +52,80 @@ jobs:
GITHUB_TOKEN: ${{ secrets.SCRUTINY_GITHUB_TOKEN }} # Leave this line unchanged
- name: Test
run: |
mkdir -p $(dirname "$PROJECT_PATH")
cp -a $GITHUB_WORKSPACE $PROJECT_PATH
cd $PROJECT_PATH
go mod vendor
go test -v -tags "static" $(go list ./... | grep -v /vendor/)
- name: Build Binaries
run: |
cd $PROJECT_PATH
make all
# restore modified dir to GH workspace.
cp -arf $PROJECT_PATH/. $GITHUB_WORKSPACE/
# copy all the build artifacts to the GH workspace
cp -arf /build/. $GITHUB_WORKSPACE/
- name: Commit Changes
make binary-clean binary-test-coverage
- name: Commit Changes Locally
id: commit
uses: packagrio/action-releasr-go@master
env:
# This is necessary in order to push a commit to the repo
GITHUB_TOKEN: ${{ secrets.SCRUTINY_GITHUB_TOKEN }} # Leave this line unchanged
with:
version_metadata_path: ${{ github.event.inputs.version_metadata_path }}
- name: Publish Release
- name: Upload workspace
uses: actions/upload-artifact@v3
with:
name: workspace
path: ${{ github.workspace }}/**/*
retention-days: 1

build:
name: Build ${{ matrix.cfg.goos }}/${{ matrix.cfg.goarch }}${{ matrix.cfg.goarm }}
needs: release
runs-on: ${{ matrix.cfg.on }}
env:
GOOS: ${{ matrix.cfg.goos }}
GOARCH: ${{ matrix.cfg.goarch }}
GOARM: ${{ matrix.cfg.goarm }}
STATIC: true
strategy:
matrix:
cfg:
- { on: ubuntu-latest, goos: linux, goarch: amd64 }
- { on: ubuntu-latest, goos: linux, goarch: arm, goarm: 5 }
- { on: ubuntu-latest, goos: linux, goarch: arm, goarm: 6 }
- { on: ubuntu-latest, goos: linux, goarch: arm, goarm: 7 }
- { on: ubuntu-latest, goos: linux, goarch: arm64 }
- { on: macos-latest, goos: darwin, goarch: amd64 }
- { on: macos-latest, goos: darwin, goarch: arm64 }
- { on: macos-latest, goos: freebsd, goarch: amd64 }
- { on: windows-latest, goos: windows, goarch: amd64 }
- { on: windows-latest, goos: windows, goarch: arm64 }
steps:
- name: Download workspace
uses: actions/download-artifact@v3
with:
name: workspace
- uses: actions/setup-go@v3
with:
go-version: '1.18.3' # The Go version to download (if necessary) and use.
- name: Build Binaries
run: |
make binary-clean binary-all
- name: Archive
uses: actions/upload-artifact@v2
with:
name: binaries.zip
path: |
scrutiny-web-*
scrutiny-collector-metrics-*
release-publish:
name: Publish Release
needs: build
runs-on: ubuntu-latest
steps:
- name: Download workspace
uses: actions/download-artifact@v3
with:
name: workspace
- name: Download binaries
uses: actions/download-artifact@v3
with:
name: binaries.zip
- name: List
shell: bash
run: |
ls -alt
- name: Publish Release & Assets
id: publish
uses: packagrio/action-publishr-go@master
env:
Expand All @@ -89,15 +134,23 @@ jobs:
with:
version_metadata_path: ${{ github.event.inputs.version_metadata_path }}
upload_assets:
scrutiny-web-linux-amd64
scrutiny-collector-metrics-darwin-amd64
scrutiny-collector-metrics-darwin-arm64
scrutiny-collector-metrics-freebsd-amd64
scrutiny-collector-metrics-linux-amd64
scrutiny-web-linux-arm64
scrutiny-collector-metrics-linux-arm-5
scrutiny-collector-metrics-linux-arm-6
scrutiny-collector-metrics-linux-arm-7
scrutiny-collector-metrics-linux-arm64
scrutiny-collector-metrics-windows-amd64.exe
scrutiny-collector-metrics-windows-arm64.exe
scrutiny-web-darwin-amd64
scrutiny-web-darwin-arm64
scrutiny-web-freebsd-amd64
scrutiny-web-linux-amd64
scrutiny-web-linux-arm-5
scrutiny-collector-metrics-linux-arm-5
scrutiny-web-linux-arm-6
scrutiny-collector-metrics-linux-arm-6
scrutiny-web-linux-arm-7
scrutiny-collector-metrics-linux-arm-7
scrutiny-web-windows-4.0-amd64.exe
scrutiny-collector-metrics-windows-4.0-amd64.exe
scrutiny-web-linux-arm64
scrutiny-web-windows-amd64.exe
scrutiny-web-windows-arm64.exe
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,15 @@ all: binary-all

.PHONY: binary-all
binary-all: binary-collector binary-web
@echo "building all"
@echo "built binary-collector and binary-web targets"


.PHONY: binary-clean
binary-clean:
go clean

.PHONY: binary-dep
binary-dep:
env
go env
go mod vendor

.PHONY: binary-test
Expand Down Expand Up @@ -102,7 +101,11 @@ binary-frontend:
npm run build:prod -- --output-path=$(CURDIR)/dist


#############
########################################################################################################################
# Docker
# NOTE: these docker make targets are only used for local development (not used by Github Actions/CI)
# NOTE: docker-web and docker-omnibus require `make binary-frontend` or frontend.tar.gz content in /dist before executing.
########################################################################################################################
.PHONY: docker-collector
docker-collector:
@echo "building collector docker image"
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,18 @@ scrutiny-collector-metrics run --debug --log-file /tmp/collector.log

# Supported Architectures


| Architecture Name | Binaries | Docker |
| --- | --- | --- |
| amd64 | :white_check_mark: | :white_check_mark: |
| arm-5 | :white_check_mark: | |
| arm-6 | :white_check_mark: | |
| arm-7 | :white_check_mark: | web/collector only. see [#236](https://github.com/AnalogJ/scrutiny/issues/236) |
| arm64 | :white_check_mark: | :white_check_mark: |
| freebsd | collector only. see [#238](https://github.com/AnalogJ/scrutiny/issues/238) | |
| linux-amd64 | :white_check_mark: | :white_check_mark: |
| linux-arm-5 | :white_check_mark: | |
| linux-arm-6 | :white_check_mark: | |
| linux-arm-7 | :white_check_mark: | web/collector only. see [#236](https://github.com/AnalogJ/scrutiny/issues/236) |
| linux-arm64 | :white_check_mark: | :white_check_mark: |
| freebsd-amd64 | collector only. see [#238](https://github.com/AnalogJ/scrutiny/issues/238) | |
| macos-amd64 | | :white_check_mark: |
| macos-arm64 | | :white_check_mark: |
| windows-amd64 | :white_check_mark: | WIP, see [#15](https://github.com/AnalogJ/scrutiny/issues/15) |
| windows-arm64 | :white_check_mark: | |


# Contributing
Expand Down
16 changes: 8 additions & 8 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
########################################################################################################################
# Omnibus Image
# NOTE: this image requires the `make binary-frontend` target to have been run before `docker build` The `dist` directory must exist.
########################################################################################################################


########
FROM golang:1.17-bullseye as backendbuild

WORKDIR /go/src/github.com/analogj/scrutiny

COPY . /go/src/github.com/analogj/scrutiny
RUN make binary-clean binary-all WEB_BINARY_NAME=scrutiny

RUN go mod vendor && \
go build -o scrutiny webapp/backend/cmd/scrutiny/scrutiny.go && \
go build -o scrutiny-collector-selftest collector/cmd/collector-selftest/collector-selftest.go && \
go build -o scrutiny-collector-metrics collector/cmd/collector-metrics/collector-metrics.go

########
FROM debian:bullseye-slim as runtime
Expand All @@ -27,18 +29,16 @@ RUN apt-get update && apt-get install -y cron smartmontools ca-certificates curl
&& curl https://github.com/just-containers/s6-overlay/releases/download/v1.21.8.0/s6-overlay-${S6_ARCH}.tar.gz -L -s --output /tmp/s6-overlay-${S6_ARCH}.tar.gz \
&& tar xzf /tmp/s6-overlay-${S6_ARCH}.tar.gz -C / \
&& rm -rf /tmp/s6-overlay-${S6_ARCH}.tar.gz \
&& curl -L https://dl.influxdata.com/influxdb/releases/influxdb2-2.2.0-${TARGETARCH}.deb --output /tmp/influxdb2-2.2.0-${TARGETARCH}.deb \
&& curl -L https://dl.influxdata.com/influxdb/relekeyases/influxdb2-2.2.0-${TARGETARCH}.deb --output /tmp/influxdb2-2.2.0-${TARGETARCH}.deb \
&& dpkg -i --force-all /tmp/influxdb2-2.2.0-${TARGETARCH}.deb

COPY /rootfs /

COPY /rootfs/etc/cron.d/scrutiny /etc/cron.d/scrutiny
COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny /opt/scrutiny/bin/
COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny-collector-selftest /opt/scrutiny/bin/
COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny-collector-metrics /opt/scrutiny/bin/
COPY dist /opt/scrutiny/web
RUN chmod +x /opt/scrutiny/bin/scrutiny && \
chmod +x /opt/scrutiny/bin/scrutiny-collector-selftest && \
chmod +x /opt/scrutiny/bin/scrutiny-collector-metrics && \
chmod 0644 /etc/cron.d/scrutiny && \
rm -f /etc/cron.daily/* && \
Expand Down
13 changes: 7 additions & 6 deletions docker/Dockerfile.collector
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
########################################################################################################################
# Collector Image
########################################################################################################################


########
FROM golang:1.17-bullseye as backendbuild

WORKDIR /go/src/github.com/analogj/scrutiny

COPY . /go/src/github.com/analogj/scrutiny

RUN go mod vendor && \
go build -ldflags '-w -extldflags "-static"' -o scrutiny-collector-selftest collector/cmd/collector-selftest/collector-selftest.go && \
go build -ldflags '-w -extldflags "-static"' -o scrutiny-collector-metrics collector/cmd/collector-metrics/collector-metrics.go
RUN make binary-clean binary-collector

########
FROM debian:bullseye-slim as runtime
Expand All @@ -18,10 +21,8 @@ RUN apt-get update && apt-get install -y cron smartmontools ca-certificates tzda

COPY /docker/entrypoint-collector.sh /entrypoint-collector.sh
COPY /rootfs/etc/cron.d/scrutiny /etc/cron.d/scrutiny
COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny-collector-selftest /opt/scrutiny/bin/
COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny-collector-metrics /opt/scrutiny/bin/
RUN chmod +x /opt/scrutiny/bin/scrutiny-collector-selftest && \
chmod +x /opt/scrutiny/bin/scrutiny-collector-metrics && \
RUN chmod +x /opt/scrutiny/bin/scrutiny-collector-metrics && \
chmod +x /entrypoint-collector.sh && \
chmod 0644 /etc/cron.d/scrutiny && \
rm -f /etc/cron.daily/apt /etc/cron.daily/dpkg /etc/cron.daily/passwd
Expand Down

0 comments on commit 4a16ca0

Please sign in to comment.