Skip to content

Commit

Permalink
Remove go generate and fix docker build (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjohnsonpint authored Oct 11, 2024
1 parent a6a1685 commit 7ea5cb0
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 114 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/cd-runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ on:
description: "releasetag"
required: true
type: string
env:
GOPRIVATE: "github.com/hypermodeinc/*"
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
Expand All @@ -25,10 +23,6 @@ jobs:
environment: "${{ github.event.inputs.environment }}"
runs-on: warp-ubuntu-latest-x64-16x
steps:
- name: Configure git for private modules
env:
TOKEN: ${{ secrets.GO_PRIVATE_MODULES }}
run: git config --global url."https://admin-hypermode:${TOKEN}@github.com".insteadOf "https://github.com"
- uses: actions/checkout@v4
with:
ref: "${{ github.event.inputs.releasetag }}"
Expand All @@ -49,7 +43,7 @@ jobs:
echo "this is NOT a release tag"
exit 1
fi
RUNTIME_RELEASE_VERSION=$(echo $GIT_TAG_NAME | sed 's/runtime-//')
RUNTIME_RELEASE_VERSION=$(echo $GIT_TAG_NAME | sed 's/^runtime\///')
echo "making a new release for runtime "$RUNTIME_RELEASE_VERSION
echo "RUNTIME_RELEASE_VERSION=$RUNTIME_RELEASE_VERSION" >> $GITHUB_ENV
- name: Runtime Git SHA
Expand All @@ -70,11 +64,13 @@ jobs:
- name: Build and push runtime docker image
uses: docker/build-push-action@v6
with:
context: "{{defaultContext}}:runtime"
context: .
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
push: true
# see https://github.com/docker/build-push-action/issues/755 for why provenance=false
provenance: false
tags: ${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_REGION }}.amazonaws.com/hypermode/runtime:${{ env.RUNTIME_RELEASE_VERSION }}-${{ env.RUNTIME_GIT_SHA }}
build-args: |
RUNTIME_RELEASE_VERSION=${{ env.RUNTIME_RELEASE_VERSION }}
2 changes: 0 additions & 2 deletions .github/workflows/ci-go-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ jobs:
with:
cache-dependency-path: "${{ matrix.dir }}/go.sum"
go-version-file: "${{ matrix.dir }}/go.mod"
- name: Generate Code
run: go generate ./...
- name: Run Linter
uses: golangci/golangci-lint-action@v6
with:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci-go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ jobs:
with:
cache-dependency-path: "${{ matrix.dir }}/go.sum"
go-version-file: "${{ matrix.dir }}/go.mod"
- name: Generate Code
run: go generate ./...
- name: Run Unit Tests
run: |
go install github.com/jstemmer/go-junit-report/v2@latest
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/ci-sdk-go-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ jobs:
with:
cache-dependency-path: "./sdk/go/go.sum"
go-version-file: "./sdk/go/go.mod"
- name: Generate Code
run: go generate ./...
- name: Build Program
run: go build .

Expand All @@ -69,7 +67,5 @@ jobs:
uses: acifani/setup-tinygo@v2
with:
tinygo-version: "0.33.0"
- name: Generate Code
run: go generate ./...
- name: Build Program
run: ./build.sh
38 changes: 20 additions & 18 deletions .github/workflows/release-runtime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@ name: "Release Runtime"
on:
push:
tags:
- 'runtime/v*'
- "runtime/v*"
permissions:
contents: "write"
jobs:
release:
runs-on: warp-ubuntu-latest-x64-4x
steps:
- name: "Validate version"
if: ${{ !startsWith(github.ref_name, 'runtime/v') }}
run: 'echo "Modus Runtime version must start with `runtime/v` && exit 1'
- uses: actions/checkout@v4
with:
ref: "${{ github.ref_name }}"
- uses: actions/setup-go@v5
with:
go-version: 1.23
- uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser-pro
version: "2.3.2"
args: release --clean -f ./runtime/.goreleaser.yaml
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
GORELEASER_KEY: "${{ secrets.GORELEASER_KEY }}"
- name: "Validate version"
if: ${{ !startsWith(github.ref_name, 'runtime/v') }}
run: 'echo "Modus Runtime version must start with `runtime/v` && exit 1'
- uses: actions/checkout@v4
with:
ref: "${{ github.ref_name }}"
- uses: actions/setup-go@v5
with:
go-version: 1.23
check-latest: true
cache-dependency-path: runtime/go.sum
- uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser-pro
version: "2.3.2"
args: release --clean -f ./runtime/.goreleaser.yaml
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
GORELEASER_KEY: "${{ secrets.GORELEASER_KEY }}"
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ In previous releases, the name "Hypermode" was used for all three._
- Use cli component instead of direct node execution modus-sdk-as [#448](https://github.com/hypermodeinc/modus/pull/448)
- Cleanup Go Modules [#450](https://github.com/hypermodeinc/modus/pull/450)
- Modularize / Rename host functions [#452](https://github.com/hypermodeinc/modus/pull/452)
- Add release pipeline for the runtime [#453](https://github.com/hypermodeinc/modus/pull/453) [#454](https://github.com/hypermodeinc/modus/pull/454)
- Remove `go generate` and fix docker build [#455](https://github.com/hypermodeinc/modus/pull/455)

## 2024-10-02 - Version 0.12.7

Expand Down
15 changes: 9 additions & 6 deletions runtime/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
FROM --platform=$BUILDPLATFORM golang:alpine AS builder
WORKDIR /src

# copy dependencies then switch to the runtime directory
COPY ./lib ./lib
WORKDIR /src/runtime

# copy go.mod and go.sum files separately so that the download step
# is only run when the dependencies change
COPY go.mod go.sum ./
COPY runtime/go.mod runtime/go.sum ./
RUN go mod download

COPY ./ ./
ARG TARGETOS TARGETARCH MODUS_BUILD_VERSION
RUN MODUS_BUILD_VERSION=$MODUS_BUILD_VERSION go generate ./...
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o modus_runtime
COPY runtime/ ./
ARG TARGETOS TARGETARCH RUNTIME_RELEASE_VERSION
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o modus_runtime -ldflags "-s -w -X github.com/hypermodeinc/modus/runtime/config.version=$RUNTIME_RELEASE_VERSION" .

# build the container image
FROM ubuntu:22.04
Expand All @@ -24,7 +27,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
less

# copy runtime binary from the build phase
COPY --from=builder /src/modus_runtime /usr/bin/modus_runtime
COPY --from=builder /src/runtime/modus_runtime /usr/bin/modus_runtime

# update certificates every build
RUN apt-get update && apt-get install -y --no-install-recommends \
Expand Down
3 changes: 3 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"classid",
"codegen",
"CODEOWNERS",
"creatordate",
"datasource",
"dbname",
"dbpool",
Expand Down Expand Up @@ -60,6 +61,7 @@
"godotenv",
"gojs",
"gomod",
"goreleaser",
"graphqlclient",
"graphqlerrors",
"greq",
Expand Down Expand Up @@ -88,6 +90,7 @@
"jsonparser",
"jsonschema",
"langsupport",
"ldflags",
"legacymodels",
"Lessable",
"linkname",
Expand Down
3 changes: 2 additions & 1 deletion runtime/.goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ git:
prerelease_suffix: "-"
before:
hooks:
- sh -c "cd runtime && go generate ./... && go mod tidy"
- sh -c "cd runtime && go mod tidy"
builds:
- main: .
binary: modus_runtime
Expand All @@ -23,6 +23,7 @@ builds:
- amd64
- arm64
mod_timestamp: "{{ .CommitTimestamp }}"
ldflags: -s -w -X github.com/hypermodeinc/modus/runtime/config.version={{.Version}}
archives:
- files:
- "../README.md"
Expand Down
25 changes: 11 additions & 14 deletions runtime/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
EXECUTABLE := modus_runtime
VERSION := $(shell git describe --tags --always --match 'runtime/*' | sed 's/^runtime\///')

ifneq ($(OS), Windows_NT)
OS := $(shell uname -s)
Expand All @@ -16,20 +17,16 @@ tidy:
go mod tidy -v
go fmt ./...

.PHONY: generate
generate:
go generate ./...

.PHONY: build
build: generate
go build -o $(EXECUTABLE)
build:
go build -o $(EXECUTABLE) -ldflags "-s -w -X github.com/hypermodeinc/modus/runtime/config.version=$(VERSION)" .

.PHONY: run
run: generate
run:
go run .

.PHONY: build-testdata
build-testdata: generate build-testdata-assemblyscript build-testdata-golang
build-testdata: build-testdata-assemblyscript build-testdata-golang

.PHONY: build-testdata-assemblyscript
build-testdata-assemblyscript:
Expand All @@ -40,28 +37,28 @@ build-testdata-golang:
cd languages/golang/testdata && ./build.sh

.PHONY: test
test: generate
test:
go test ./...

.PHONY: test-no-cache
test-no-cache: generate
test-no-cache:
go test -count=1 ./...

.PHONY: test-race
test-race: generate
test-race:
go test -race ./...

.PHONY: test-integration
test-integration:
go test -race -tags=integration -count=1 ./integration_tests/...

.PHONY: test-ci
test-ci: generate
test-ci:
go install github.com/jstemmer/go-junit-report/v2@latest
go test -v -race 2>&1 ./... | go-junit-report -set-exit-code -iocopy -out report.xml

.PHONY: test-integration-ci
test-integration-ci: generate
test-integration-ci:
go install github.com/jstemmer/go-junit-report/v2@latest
go test -tags integration -v -race 2>&1 ./integration_tests/... | go-junit-report -set-exit-code -iocopy -out report.xml

Expand All @@ -73,4 +70,4 @@ clean:

.PHONY: docker-build
docker-build:
docker build --build-arg MODUS_BUILD_VERSION="$(shell git describe --tags --always)" -t modus_runtime .
cd .. && docker build --build-arg RUNTIME_RELEASE_VERSION="$(VERSION)" -t modus_runtime .
33 changes: 28 additions & 5 deletions runtime/config/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,36 @@

package config

func GetProductVersion() string {
return "Modus Runtime " + GetVersionNumber()
import (
"os/exec"
"strings"
)

var version string

func init() {
// The "version" variable is set by the makefile using -ldflags when using "make build" or goreleaser.
// If it is not set, then we are running in development mode with "go run" or "go build" without the makefile,
// so we will describe the version from git at run time.
if version == "" {
version = describeVersion()
} else if version[0] >= '0' && version[0] <= '9' {
version = "v" + version
}
}

func GetVersionNumber() string {
// If you see an undefined error on the following line, you need to run "go generate" in the runtime directory.
// You can also use "make generate", "make build", or "make run", or launch in VS Code.

return version
}

func GetProductVersion() string {
return "Modus Runtime " + GetVersionNumber()
}

func describeVersion() string {
result, err := exec.Command("git", "describe", "--tags", "--always", "--match", "runtime/*").Output()
if err != nil {
return "(unknown)"
}
return strings.TrimPrefix(strings.TrimSpace(string(result)), "runtime/")
}
2 changes: 0 additions & 2 deletions runtime/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

//go:generate go run ./tools/generate_version

package main

import (
Expand Down
52 changes: 0 additions & 52 deletions runtime/tools/generate_version/genversion.go

This file was deleted.

0 comments on commit 7ea5cb0

Please sign in to comment.