Repository: compose-spec/compose-go
Pull request #746 (2025-02-23 17:52:23)

fix loading gw_priority
Forgot to run `make deepcopy` - I always do adding new attributes. So I added a validation step to check this in CI, also updated make targets to run commands in a container vs local tools installation

closes https://github.com/docker/compose/issues/12574



Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 308b186..8f65aea 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -14,6 +14,12 @@ jobs:
         uses: actions/checkout@v4
       - name: Check license
         run: DOCKER_BUILDKIT=1 make check-license
+      - name: Check deepcopy
+        run: |
+          make deepcopy
+          if [ -n "$(git status --porcelain)" ]; then
+            echo >&2 'ERROR: DeepCopy is not up to date with code. Please run "make deepcopy"'
+          fi
 
   test:
     strategy:
diff --git a/Makefile b/Makefile
index 7c94b28..af143ff 100644
--- a/Makefile
+++ b/Makefile
@@ -31,9 +31,8 @@ fmt: ## Format go files
 	go fmt ./...
 
 .PHONY: deepcopy
-deepcopy:
-	goderive -h >/dev/null 2>&1 || go install github.com/awalterschulze/goderive@0a721d5b1d722ae6ba0dddefa1200607ca3ece97
-	goderive ./types/...
+deepcopy: build-validate-image
+	docker run --rm -v .:/go/src $(IMAGE_PREFIX)validate goderive ./types/...
 
 .PHONY: build-validate-image
 build-validate-image:
@@ -41,11 +40,11 @@ build-validate-image:
 
 .PHONY: lint
 lint: build-validate-image
-	docker run --rm $(IMAGE_PREFIX)validate bash -c "golangci-lint run --config ./.golangci.yml ./..."
+	docker run --rm -v .:/go/src $(IMAGE_PREFIX)validate golangci-lint run --config ./.golangci.yml ./...
 
 .PHONY: check-license
 check-license: build-validate-image
-	docker run --rm $(IMAGE_PREFIX)validate bash -c "./scripts/validate/fileheader"
+	docker run --rm -v .:/go/src $(IMAGE_PREFIX)validate ltag -t scripts/validate/template --excludes "validate dotenv" --check -v
 
 .PHONY: setup
 setup: ## Setup the precommit hook
diff --git a/ci/Dockerfile b/ci/Dockerfile
index dedd69b..07db471 100644
--- a/ci/Dockerfile
+++ b/ci/Dockerfile
@@ -12,12 +12,12 @@
 #   See the License for the specific language governing permissions and
 #   limitations under the License.
 
-FROM golang:1.23
+FROM golang:1.24
 
 WORKDIR /go/src
 
 ARG GOLANGCILINT_VERSION=v1.64.5
 RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCILINT_VERSION}
 RUN go install github.com/kunalkushwaha/ltag@latest && rm -rf /go/src/github.com/kunalkushwaha
-
-COPY . .
+RUN go install github.com/awalterschulze/goderive@v0.5.1
+RUN go install github.com/kunalkushwaha/ltag@v0.2.5
diff --git a/scripts/validate/fileheader b/scripts/validate/fileheader
deleted file mode 100755
index ce32e87..0000000
--- a/scripts/validate/fileheader
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/usr/bin/env bash
-
-#   Copyright The Compose Specification Authors.
-
-#   Licensed under the Apache License, Version 2.0 (the "License");
-#   you may not use this file except in compliance with the License.
-#   You may obtain a copy of the License at
-
-#       http://www.apache.org/licenses/LICENSE-2.0
-
-#   Unless required by applicable law or agreed to in writing, software
-#   distributed under the License is distributed on an "AS IS" BASIS,
-#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#   See the License for the specific language governing permissions and
-#   limitations under the License.
-
-
-set -eu -o pipefail
-
-if ! command -v ltag; then
-    >&2 echo "ERROR: ltag not found. Install with:"
-    >&2 echo "    go get -u github.com/kunalkushwaha/ltag"
-    exit 1
-fi
-
-BASEPATH="${1-}"
-
-ltag -t "${BASEPATH}scripts/validate/template" --excludes "validate dotenv" --check -v
diff --git a/types/derived.gen.go b/types/derived.gen.go
index 445d1cd..d4b8257 100644
--- a/types/derived.gen.go
+++ b/types/derived.gen.go
@@ -1812,6 +1812,7 @@ func deriveDeepCopy_38(dst, src *DeviceRequest) {
 // deriveDeepCopy_39 recursively copies the contents of src into dst.
 func deriveDeepCopy_39(dst, src *ServiceNetworkConfig) {
 	dst.Priority = src.Priority
+	dst.GatewayPriority = src.GatewayPriority
 	if src.Aliases == nil {
 		dst.Aliases = nil
 	} else {


Test patch:
diff --git a/loader/loader_test.go b/loader/loader_test.go
index cd08d1f..a1afd74 100644
--- a/loader/loader_test.go
+++ b/loader/loader_test.go
@@ -3706,3 +3706,16 @@ services:
 	assert.Equal(t, len(p.Services["test"].Gpus), 1)
 	assert.Equal(t, p.Services["test"].Gpus[0].Count, types.DeviceCount(-1))
 }
+
+func TestGwPriority(t *testing.T) {
+	p, err := loadYAML(`
+name: load-gw_priority
+services:
+  test:
+    networks:
+      test:
+        gw_priority: 42
+`)
+	assert.NilError(t, err)
+	assert.Equal(t, p.Services["test"].Networks["test"].GatewayPriority, 42)
+}