Skip to content

Standard project structure#21

Merged
LarsTi merged 1 commit into
LarsTi:mainfrom
erikns:erikns/canonical-structure
Apr 10, 2025
Merged

Standard project structure#21
LarsTi merged 1 commit into
LarsTi:mainfrom
erikns:erikns/canonical-structure

Conversation

@erikns
Copy link
Copy Markdown
Contributor

@erikns erikns commented Feb 28, 2025

This PR introduces a more standardized Go module structure, making it easier to build and work with. I realize it might be a bit "disruptive", but I think it's a good idea.

  • The code in the app/ folder is moved out to the project root.
  • The module definition file used an unrelated GitHub URL. This is changed.
  • Bumped minimum Go version to 1.21 as the dependency github.com/prometheus/client_golang (at least when downloaded in the original Dockerfile seemed to require it.
  • The Dockerfile is retooled to build with this new structure.

There is also a small change to the message loop in main(), I guess caused by a breaking change in the later version of govici.


Using the new structure it is now trivial to build both "natively" or in Docker.

Natively:

  • Clone
  • go mod download
  • go build -o ipsec-exporter .

Docker:

  • docker build [...]

Cross-compilations are just as simple, should it be required.

Change structure to make it closer to the standard Go module structure.

Change module definition file to reflect repo location.

Retool Dockerfile to build from this new structure

To compile the minimum Go version had to be bumped from 1.18 to 1.21, as github.com/prometheus/client_golang (as downloaded by the original Dockerfile) required it to build.
@LarsTi
Copy link
Copy Markdown
Owner

LarsTi commented Mar 1, 2025

Hey, i appreciate your work.
Temporarly i am very busy and wont get into it before eastern 2025. But i will try to check in and see at your changes.
Do you know, why the go sum file is in the commit? i was trying to keep it small and let go build the sum file in the container itself.
Thanks for your help! :)

@erikns
Copy link
Copy Markdown
Contributor Author

erikns commented Mar 2, 2025

I thought this project might be useful, so I figured I'd contribute back.

Do you know, why the go sum file is in the commit?

The short answer is that it enables reproducible builds, by ensuring that everyone uses the exact same versions of all dependencies. With it committed, you get the same deps (or at least you have the means to verify it) inside and outside Docker as well. Check here for some official rationale about committing the go.sum file.

@LarsTi
Copy link
Copy Markdown
Owner

LarsTi commented Mar 2, 2025

I will try to merge this tommorrow when i can check this in my dev system.
Thanks for your work!

I tried to abstract the go.sum so you can just rebuild the image and all the newest components get pulled directly.
You have any ideas, how we can achieve this?

@erikns
Copy link
Copy Markdown
Contributor Author

erikns commented Mar 4, 2025

Do you mean the build process should get the "latest" versions automatically?

There are go mod commands to "upgrade" dependency versions, but they all involve changing what is in the go.mod / go.sum file. The references need to be stable. As far as I know there is no "semver"-trick you can do like in a package.json of NodeJS.

So, I don't think there is a simple command that will do this automatically as the Go developers seem to favor reproducibility and stability over simplistic upgrades. (These are good reasons too, in my view, given the tasks that Go was made to solve)

As an example, you should be able to list available upgrades with:

go list -m -u all

My suggestion is to use a GitHub action to "vet" the dependencies using the go tools and some scripting, and maybe automatically add a GitHub issue if there is a big enough version bump in a dependency. It would not surprise me if someone somewhere have already made a tool for this and open-sourced it. As with almost anything else...

@LarsTi LarsTi merged commit f7c0383 into LarsTi:main Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants