canonical / rockcraft

Tool to create OCI Images using the language from Snapcraft and Charmcraft.
GNU General Public License v3.0
35 stars 43 forks source link

The `go` build-snap doesn't install the requested go version #128

Closed gruyaume closed 1 year ago

gruyaume commented 2 years ago

Description

Using the go build-snap doesn't allow for using the specified go version. The go version installed is always 1.19.

Example

rockcraft.yaml:

  golang:
    plugin: nil
    build-snaps:
      - go/1.13/stable
    override-build: |
      set -x
      go version
      craftctl default
      go version

Execution output:

guillaume@thinkpad:~/PycharmProjects/magma-controller-rock$ rockcraft pack -v
Starting Rockcraft 0.0.1.dev1                                                                                                                                                                                                                          
Logging execution to '/home/guillaume/.cache/rockcraft/log/rockcraft-20221013-170003.209576.log'                                                                                                                                                       
Launching instance...                                                                                                                                                                                                                                  
Starting Rockcraft 0.0.1.dev1                                                                                                                                                                                                                          
Logging execution to '/tmp/rockcraft.log'                                                                                                                                                                                                              
Retrieving base ubuntu:18.04                                                                                                                                                                                                                           
Retrieved base ubuntu:18.04 for amd64                                                                                                                                                                                                                  
Extracting ubuntu:18.04                                                                                                                                                                                                                                
Extracted ubuntu:18.04                                                                                                                                                                                                                                 
Initializing parts lifecycle                                                                                                                                                                                                                           
Executing parts lifecycle                                                                                                                                                                                                                              
Executing parts lifecycle: pull golang                                                                                                                                                                                                                 
Executing action                                                                                                                                                                                                                                       
Executed: pull golang                                                                                                                                                                                                                                  
Executing parts lifecycle: skip pull pebble (already ran)                                                                                                                                                                                              
Executing action                                                                                                                                                                                                                                       
Executed: skip pull pebble (already ran)                                                                                                                                                                                                               
Executing parts lifecycle: overlay golang                                                                                                                                                                                                              
Executing action                                                                                                                                                                                                                                       
Executed: overlay golang                                                                                                                                                                                                                               
Executing parts lifecycle: reapply pebble (previous layer changed)                                                                                                                                                                                     
Executing action                                                                                                                                                                                                                                       
Executed: reapply pebble (previous layer changed)                                                                                                                                                                                                      
Executing parts lifecycle: build golang                                                                                                                                                                                                                
Executing action                                                                                                                                                                                                                                       
:: + set -x                                                                                                                                                                                                                                            
:: + go version                                                                                                                                                                                                                                        
:: go version go1.19 linux/amd64                                                                                                                                                                                                                       
:: + craftctl default                                                                                                                                                                                                                                  
:: + go version                                                                                                                                                                                                                                        
:: go version go1.19 linux/amd64

Workaround

Add snap commands as an override-build that will switch the go version

snap switch go --channel=1.12/stable
snap refresh go
tigarmo commented 2 years ago

Thanks for the report! I was able to reproduce this, and I believe the issue is with the pebble "implicit part" that we add in every rockcraft part. It uses go/1.19/stable and it looks like we install all build-snaps for all parts in one step. If I repackage rockcraft without the pebble part I get the expected behavior:

Executing parts lifecycle: build golang                                                                                                                                                                                                    
Executing action                                                                                                                                                                                                                           
:: + set -x                                                                                                                                                                                                                                
:: + go version                                                                                                                                                                                                                            
:: go version go1.13.15 linux/amd64                                                                                                                                                                                                        
:: + craftctl default                                                                                                                                                                                                                      
:: + go version                                                                                                                                                                                                                            
:: go version go1.13.15 linux/amd64

I don't know a straightforward fix for this, I suppose it would happen in any situation where different parts define different versions of the same snap in their build-snaps. Maybe we could do the switch/refresh step for every snap that a part declares, in their build "preamble"?

tigarmo commented 2 years ago

Alternatively, for go specifically, a "workaround" might be to lower the version that we use to build the pebble part. It looks like the minimum version is 1.14 so it still wouldn't help us in this specific case.

sergiusens commented 1 year ago

this was fixed with #144