Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) by nld3-dev1.alpinelinux.org (Postfix) with ESMTPS id 1BC97782C09 for <~alpine/devel@lists.alpinelinux.org>; Wed, 11 Sep 2019 19:15:02 +0000 (UTC) Received: by mail-yb1-f180.google.com with SMTP id u32so7738223ybi.12 for <~alpine/devel@lists.alpinelinux.org>; Wed, 11 Sep 2019 12:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=32l0ltHUC7lIk3zCPlAc7xLmquB+m6neMZhE6eKfE4E=; b=RIKE59E3s0D2CaPa/WxLnrcZrA+390MevXUfpX1uqSsmw5gngd9ysOm5et9Fhf1J4c rN+mzJdNiUYcBsc/77boiD2POuxIh8qXW8eN8yVdN6s+yeF5B+VGsFaCEk9l88Z8m3ZZ kEuEKdXiIoS5YQXw+S9KagEVF9xCfWDwD9KgSEqZ6Iufz3fkkR3TNdxh3elN2tYZmL4r 7RbnQAG9ztkkIWKZGSjzRFpiGLXHX6sZ4O2jLW30Z/9MXqk3qIAKdnPPOZWKS/NTKCvO rgRAM84NSpDD84VB1xqiumaxedDp4py4Z1+0AZ7dQ+3sx5jNPE2cuGNoro/0AvnKl+6d yy3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=32l0ltHUC7lIk3zCPlAc7xLmquB+m6neMZhE6eKfE4E=; b=sSA8pxAX/fevCQKfjjhN83yy9Hz/ohkVU4mnSJlhCUeDI8dQmmjb8azS5ztg3tDmHm YSYgpWmWRNqX7s1QMwftT6sB/1cXseiy5XlW9lspb03/440EodQ0SsmEoTVG6CLcVUtf pj6JqIvMl7F5Z0lymJD6QNDPIDNGVd6bSRW5DEh0gJa+sowrsnhyJZIosM9JEeO7xX8D wxJ7TREne0aaDKtn0Wdnt4m3b1B+NbOZRlxEhCUS9cwF05RJF56VaKlbgu4+CzCcMy6f 5myRn6fz/fIypNgb55iJAt2M5kQRPEzCgb9PADsaxdkWc+inz3HC8cEvluvcX5q1lOTf RDNQ== X-Gm-Message-State: APjAAAUa4A5QSp3MMmWozmAAMStvuHlL4lATep4gHobym2zvSTI9Vvse pfqiFB6D815TTPrbhpTXu6psNyYWZ1Ghi/a4T+K4YYh9 X-Google-Smtp-Source: APXvYqxQ2+sgyuEfsumPWisI1aYcQc0SkDxlPR4SoJoLQpy3KlDLh5I1l4EkY799/2EtU3OnEN4cY+OsVeNmqL4g3mw= X-Received: by 2002:a25:2bc8:: with SMTP id r191mr24174657ybr.327.1568229301470; Wed, 11 Sep 2019 12:15:01 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Konstantin Kulikov Date: Wed, 11 Sep 2019 19:14:50 +0000 Message-ID: Subject: Re: Packaging go projects To: ~alpine/devel@lists.alpinelinux.org Content-Type: text/plain; charset="UTF-8" Working with abuild a bit more I've came up with a simpler way. Instead of redefining fetch, making it depend on go and putting stuff in SRCDEST, we can instead define a few env vars in APKBUILD like this: export GOPROXY=${GOPROXY:-https://proxy.golang.org} # Default in go1.13 and can be removed. export GOPATH=${GOPATH:-$srcdir/go} export GOCACHE=${GOCACHE:-$srcdir/go-build} export GOTMPDIR=${GOTMPDIR:-$srcdir} This way "go build" will download modules from GOPROXY and place all build files inside srcdir. Hoverwer if user has those vars in their environment (ie local dev machine) or in abuild.conf (ie ci checks or build server), they will be used instead. This way devs work as they usually do (no difference between running "go build" manually and from abuild) and CI can opt in into module and/or build caches if they want to remove calls to external network and speed up builds. Build cache has one case when it doesn't always rebuild packages when it should so enabling it on build servers now might be problematic. https://github.com/golang/go/issues/24355 Module cache should work well. I've updated my example: https://github.com/alpinelinux/aports/commit/ac34f80cdadd78523fde160e1bbc032dd04bfbca Previous version is here: https://github.com/alpinelinux/aports/commit/7892cf94cd917c080a0c381caf5ac5e90aa84c97 On Wed, Jul 31, 2019 at 7:59 PM Konstantin Kulikov wrote: > > Hey everyone. > > I'm trying to package a go project which uses modules. This is what I > came up with. > > https://github.com/alpinelinux/aports/pull/9800 > > Notes below: > 1. fetch() depends on go command which means that abuild checksum will > fail if go is not installed. > 2. $SRCDEST will contain "go" directory with module archives using > layout defined by goproxy protocol (see > https://godoc.org/cmd/go#hdr-Module_proxy_protocol). The good thing is > that directory can be served over http and used as real GOPROXY, > avoiding contacting google or other proxies unnecessarily. Current go > projects in aports run "glide install" or "dep ensure" inside > prepare() or build() and do not cache sources at all. > 3. GOPROXY should be defined in abuild.conf and default to > https://proxy.golang.org or any other proxy to avoid depending on > git,svn,bzr and others and allow users to use their own proxies > (googles proxy is unavailable in China for example). > 4. sha512sums doesn't record hashes of module files, instead they are > recorded in go.sum file and go tool verifies them itself. > 5. chmod line in fetch() is unfortunate, without it cleanup step will > fail. Go devs previously refused to add option to make unpacked module > files writable. > 6. fetch() will be the same for every go project and can be defined in > abuild and used with options="gomodule" for example, same goes for > GOPATH var which should be set to the same value for all steps. > 7. To build a project we create dummy module which I called "apk" (but > can be any name). It allows to record exact version of every used > dependency, selectively upgrade or replace those dependencies and > record that info in binaries (it can be inspected using > rsc.io/goversion or, since go 1.13, "go version"). > 8. Patching is undoable in a way it's done in alpine (using .patch > files) because checksums are recorded in binaries and can be verified > against google's sumdb. Instead maintainer will need to fork project, > apply patches, tag release and use their fork in APKBUILD. > 9. To create new package contibutor would need to create apk.go and > "blank import" all binaries in it, run "go mod init apk && go mod > tidy", then write APKBUILD as usual. > 10. To update a package `go get $(go list -f '{{ join .Imports " " > }}')` can be used. If specific version is wanted instead of @latest, > run manually "go get github.com/9seconds/mtg@v0.16" > > Does this look sane to you? Should we package it like this? Any other ideas?