Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't redirect the output of go run to a file #755

Open
kian99 opened this issue Nov 19, 2024 · 0 comments
Open

Can't redirect the output of go run to a file #755

kian99 opened this issue Nov 19, 2024 · 0 comments

Comments

@kian99
Copy link

kian99 commented Nov 19, 2024

Bug Description

When running in the override-build step, the output of go run is not being redirected to a file as expected. In my override-build step I am using a go package to do some formatting on a file.

As I was typing out this bug report, I realised that I think this is happening because of snap confinement. It feels a bit frustrating to face snap confinement issues while in a build environment.

To Reproduce

Use the rockcraft.yaml below and put an exit 1 at the start of override-build and run rockcraft pack --debug.
Then try the following:

  • go run github.com/openfga/cli/cmd/fga@latest model -h
  • go run github.com/openfga/cli/cmd/fga@latest model -h > test-file
  • ls -lah test-file
  • go install github.com/openfga/cli/cmd/fga@latest
  • /root/go/bin/fga model -h > test-file
  • ls -lah test-file

On my machine:

# go run github.com/openfga/cli/cmd/fga@latest model -h > test-file
# ls -lah test-file
-rw-r--r-- 1 root root 0 Nov 19 12:31 test-file

# /root/go/bin/fga -h > test-file
# ls -lah test-file
-rw-r--r-- 1 root root 1.5K Nov 19 12:35 test-file

As you can see the first attempt results in an empty file (maybe because of snap confinement?) while the second attempt works.

Environment

$ lxc version
Client version: 6.1
Server version: 6.1

rockcraft.yaml

name: jimm
base: [email protected]
version: '0.1'
summary: Juju Intelligent Model Manager provides a convient way to manage all of your models!
description: |
    JIMM is a Juju controller, used in conjunction with the JaaS dashboard to provide a seamless way
    to manage models, regardless of where their controllers reside or what cloud they may be running on.

license: GPL-3.0
platforms:
    amd64:

parts:
    ca-certs:
        plugin: nil
        overlay-packages: [ca-certificates]
    builder: 
        plugin: go # https://canonical-craft-parts--694.com.readthedocs.build/en/694/common/craft-parts/reference/plugins/go_plugin.html
        after:
          - ca-certs
        source: .
        source-type: local
        build-snaps:
          - go/1.23/stable
        build-packages:
          - git
          - make 
        build-environment:
            - GOOS: linux
        override-build: |
            set -ex

            mkdir -p $CRAFT_PART_INSTALL/usr/local/bin

            make build/server
            cp ./jimmsrv $CRAFT_PART_INSTALL/usr/local/bin

            # The location of SQL files isn't configurable right now, as such we just 
            # place it in bin
            cp -r ./internal/dbmodel/sql $CRAFT_PART_INSTALL/usr/local/bin/sql

            # Convert the OpenFGA auth model to JSON and place a copy in the ROCK
            # Used by the charm to apply to the OpenFGA server, not by the container itself
            mkdir -p $CRAFT_PART_INSTALL/root/openfga/
            go install github.com/openfga/cli/cmd/fga@latest
            go run github.com/openfga/cli/cmd/fga@latest model transform --file ./openfga/authorisation_model.fga --output-format json > $CRAFT_PART_INSTALL/root/openfga/authorisation_model.json
            exit 1

Relevant log output

None
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

No branches or pull requests

1 participant