Skip to content

Commit

Permalink
Chore: remove hardcoded go version (#5258)
Browse files Browse the repository at this point in the history
* Chore: Rmove hardcoded go version

* use mimir build image as reference

* fix comments

* address comments

* Revert "address comments"

This reverts commit c06e3f3.

* add makefile

* workflow fix
  • Loading branch information
ying-jeanne authored Jun 21, 2023
1 parent aff210a commit 7d7c404
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 11 deletions.
30 changes: 29 additions & 1 deletion .github/workflows/compare-helm-with-jsonnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,41 @@ concurrency:
cancel-in-progress: true

jobs:
prepare:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Get build image from Makefile
id: build_image_step
run: echo "build_image=$(make print-build-image)" >> "$GITHUB_OUTPUT"
outputs:
build_image: ${{ steps.build_image_step.outputs.build_image }}

goversion:
runs-on: ubuntu-latest
needs: prepare
container:
image: ${{ needs.prepare.outputs.build_image }}
steps:
- uses: actions/checkout@v3
- name: Run Git Config
run: git config --global --add safe.directory '*'
- name: Get Go Version
id: go-version
run: |
echo "version=$(make BUILD_IN_CONTAINER=false print-go-version)" >> "$GITHUB_OUTPUT"
outputs:
version: ${{ steps.go-version.outputs.version }}

compare-manifests:
runs-on: ubuntu-latest
needs: goversion
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.20.5'
go-version: ${{ needs.goversion.outputs.version }}
- uses: helm/[email protected]
- name: Download yq
uses: dsaltares/fetch-gh-release-asset@a40c8b4a0471f9ab81bdf73a010f74cc51476ad4
Expand Down
23 changes: 19 additions & 4 deletions .github/workflows/test-build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,25 @@ jobs:
outputs:
build_image: ${{ steps.build_image_step.outputs.build_image }}

goversion:
runs-on: ubuntu-latest
needs: prepare
container:
image: ${{ needs.prepare.outputs.build_image }}
steps:
- uses: actions/checkout@v3
- name: Run Git Config
run: git config --global --add safe.directory '*'
- name: Get Go Version
id: go-version
run: |
echo "version=$(make BUILD_IN_CONTAINER=false print-go-version)" >> "$GITHUB_OUTPUT"
outputs:
version: ${{ steps.go-version.outputs.version }}

lint:
runs-on: ubuntu-latest
needs:
- prepare
needs: prepare
container:
image: ${{ needs.prepare.outputs.build_image }}
steps:
Expand Down Expand Up @@ -302,7 +317,7 @@ jobs:
path: ./images.tar

integration:
needs: build
needs: [goversion, build]
runs-on: ubuntu-latest
strategy:
# Do not abort other groups when one fails.
Expand All @@ -315,7 +330,7 @@ jobs:
- name: Upgrade golang
uses: actions/setup-go@v4
with:
go-version: 1.20.5
go-version: ${{ needs.goversion.outputs.version }}
cache: false # We manage caching ourselves below to maintain consistency with the other jobs that don't use setup-go.
- name: Check out repository
uses: actions/checkout@v3
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ GOVOLUMES= -v mimir-go-cache:/go/cache \
# Mount local ssh credentials to be able to clone private repos when doing `mod-check`
SSHVOLUME= -v ~/.ssh/:/root/.ssh:$(CONTAINER_MOUNT_OPTIONS)

exes $(EXES) protos $(PROTO_GOS) lint lint-packaging-scripts test test-with-race cover shell mod-check check-protos doc format dist build-mixin format-mixin check-mixin-tests license check-license conftest-fmt check-conftest-fmt helm-conftest-test helm-conftest-quick-test conftest-verify check-helm-tests build-helm-tests: fetch-build-image
exes $(EXES) protos $(PROTO_GOS) lint lint-packaging-scripts test test-with-race cover shell mod-check check-protos doc format dist build-mixin format-mixin check-mixin-tests license check-license conftest-fmt check-conftest-fmt helm-conftest-test helm-conftest-quick-test conftest-verify check-helm-tests build-helm-tests print-go-version: fetch-build-image
@echo ">>>> Entering build container: $@"
$(SUDO) time docker run --rm $(TTY) -i $(SSHVOLUME) $(GOVOLUMES) $(BUILD_IMAGE) GOOS=$(GOOS) GOARCH=$(GOARCH) BINARY_SUFFIX=$(BINARY_SUFFIX) $@;

Expand Down Expand Up @@ -323,6 +323,9 @@ format: ## Run gofmt and goimports.
test: ## Run all unit tests.
go test -timeout 30m ./...

print-go-version: ## Print the go version.
@go version | awk '{print $$3}' | sed 's/go//'

test-with-race: ## Run all unit tests with data race detect.
go test -tags netgo -timeout 30m -race -count 1 ./...

Expand Down
4 changes: 2 additions & 2 deletions development/mimir-microservices-mode/compose-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
set -e

SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)

BUILD_IMAGE=$(make -s -f ${SCRIPT_DIR}/../../Makefile print-build-image)
# Make sure docker-compose.yml is up-to-date.
cd $SCRIPT_DIR && make

# -gcflags "all=-N -l" disables optimizations that allow for better run with combination with Delve debugger.
# GOARCH is not changed.
CGO_ENABLED=0 GOOS=linux go build -mod=vendor -gcflags "all=-N -l" -o ${SCRIPT_DIR}/mimir ${SCRIPT_DIR}/../../cmd/mimir
docker-compose -f ${SCRIPT_DIR}/docker-compose.yml build distributor-1
docker-compose -f ${SCRIPT_DIR}/docker-compose.yml build --build-arg BUILD_IMAGE=${BUILD_IMAGE} distributor-1
docker-compose -f ${SCRIPT_DIR}/docker-compose.yml up $@
3 changes: 2 additions & 1 deletion development/mimir-microservices-mode/dev.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM golang:1.20.5
ARG BUILD_IMAGE # Use ./compose-up.sh to build this image.
FROM $BUILD_IMAGE
ENV CGO_ENABLED=0
RUN go install github.com/go-delve/delve/cmd/[email protected]

Expand Down
3 changes: 2 additions & 1 deletion development/mimir-read-write-mode/compose-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
set -e

SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
BUILD_IMAGE=$(make -s -f ${SCRIPT_DIR}/../../Makefile print-build-image)

# Make sure docker-compose.yml is up-to-date.
cd $SCRIPT_DIR && make

# -gcflags "all=-N -l" disables optimizations that allow for better run with combination with Delve debugger.
# GOARCH is not changed.
CGO_ENABLED=0 GOOS=linux go build -mod=vendor -gcflags "all=-N -l" -o ${SCRIPT_DIR}/mimir ${SCRIPT_DIR}/../../cmd/mimir
docker-compose -f ${SCRIPT_DIR}/docker-compose.yml build mimir-write-1
docker-compose -f ${SCRIPT_DIR}/docker-compose.yml build --build-arg BUILD_IMAGE=${BUILD_IMAGE} mimir-write-1
docker-compose -f ${SCRIPT_DIR}/docker-compose.yml up $@
3 changes: 2 additions & 1 deletion development/mimir-read-write-mode/dev.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM golang:1.20.5
ARG BUILD_IMAGE # Use ./compose-up.sh to build this image.
FROM $BUILD_IMAGE
ENV CGO_ENABLED=0
RUN go install github.com/go-delve/delve/cmd/[email protected]

Expand Down

0 comments on commit 7d7c404

Please sign in to comment.