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

Issues consolidation and optimizations #24

Merged
merged 94 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 90 commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
cf79c91
Update go and dependencies
mikusaq Jul 17, 2024
061bfae
doc typos fix
mikusaq Jul 19, 2024
8687195
Add tar functionality, copy file optimized
mikusaq Jul 19, 2024
59c0dc6
Reduce logs
mikusaq Jul 22, 2024
516e701
Add handling error states
mikusaq Jul 22, 2024
2b4c651
Add custom logging
mikusaq Jul 28, 2024
831c0a9
Replace deprecated function from ioutil package
mikusaq Jul 28, 2024
43e1b06
Remove debug logging
mikusaq Jul 28, 2024
834e77d
Reduce abstraction, refactor
mikusaq Jul 29, 2024
ee35f78
Fix logging of different versions of same package
mikusaq Jul 29, 2024
1a6c17f
Replace deprecated code
mikusaq Jul 29, 2024
196abff
Simplify method for creating package name
mikusaq Aug 12, 2024
33fadf8
Add check for error
mikusaq Aug 12, 2024
36b9c0a
Add check for available port
mikusaq Aug 12, 2024
20b096a
Unify JSON format across all packages
Mayt34 Aug 12, 2024
ee5cd7a
Update READMEs
Mayt34 Aug 12, 2024
f0fa5f8
Merge pull request #1 from Mayt34/BAF-856/packager-update
mikusaq Aug 12, 2024
4900bfc
Update doc
Mayt34 Aug 13, 2024
be060d2
Add check for overwriting sysroot files
mikusaq Aug 14, 2024
18a97c5
Update Package JSON README
Mayt34 Aug 14, 2024
989c900
Rework of package name getters
mikusaq Aug 14, 2024
6a43a27
Rework of empty sysroot directory check
mikusaq Aug 14, 2024
90dcb19
Merge pull request #2 from Mayt34/BAF-856/packager-update
mikusaq Aug 15, 2024
491e5cd
Add --build-deps flag, refactor, doc update
mikusaq Aug 15, 2024
f4c1540
Move getting package with deps paths to ContextManager
mikusaq Aug 19, 2024
ea0c690
Add file logging to build-image command, refactor
mikusaq Aug 19, 2024
abcbe53
Add method doc
mikusaq Aug 19, 2024
12c2485
Add state logs and log for succesfull builds
mikusaq Aug 19, 2024
c709700
Add indent logging
mikusaq Aug 19, 2024
e19ed27
Remove CopyRecursive - not used
mikusaq Aug 21, 2024
da63695
Change directory name of logs
mikusaq Aug 21, 2024
452e943
Remove unused timestamp from ContextLogger
mikusaq Aug 21, 2024
e71675d
Check only for platform specific sysroot dir
mikusaq Aug 21, 2024
f8e057e
Script exits after failed build when building Single package now
mikusaq Aug 21, 2024
965140f
Better error handling
mikusaq Aug 21, 2024
ef89ca5
Add sigint handling
mikusaq Sep 11, 2024
2c924f3
Handler remover function called without defer
mikusaq Sep 17, 2024
c4d54ce
Unify log strings
mikusaq Sep 17, 2024
f1574ab
Remove not needed logs
mikusaq Sep 17, 2024
df08365
Remove unused import
mikusaq Sep 17, 2024
53e0221
Add error state for build-deps and all flags used simultaneously
mikusaq Sep 17, 2024
8258e25
Fix logging more errors and redundant brackets
mikusaq Sep 17, 2024
e03af07
Remove redundant build log with --all
mikusaq Sep 17, 2024
f2ad0db
Add logs when building single package
mikusaq Sep 18, 2024
77a025d
Add ErrorIndent function
mikusaq Sep 18, 2024
621ee77
DockerMode refactor
mikusaq Sep 18, 2024
70dae6f
Add comment about absent SIGINT handler
mikusaq Sep 18, 2024
ac7106c
Doc update in ContextManager
mikusaq Sep 23, 2024
58c8cb2
Doc update in PackageMode
mikusaq Sep 23, 2024
4419688
Add doc to bringauto_log module
mikusaq Sep 23, 2024
fe056d6
bringauto_log module refactor
mikusaq Sep 23, 2024
86d8fc5
Change indent const to byte encoding
mikusaq Sep 23, 2024
1ef47dc
Add handling error
mikusaq Sep 24, 2024
4cbc3e4
Add doc to Tar.go
mikusaq Sep 24, 2024
44abe30
ContextManager refactor
mikusaq Sep 24, 2024
0cc9ecc
Move constants used by multiple modules to new module
mikusaq Sep 25, 2024
7045109
Doc fixed
mikusaq Sep 26, 2024
051bd8a
Refactor using PlatformString
mikusaq Sep 27, 2024
9b9770d
Change of sysroot check
mikusaq Sep 27, 2024
fc03f93
Rename SignalHandler functions
mikusaq Sep 27, 2024
9184f7a
Better error message
mikusaq Sep 27, 2024
0ec198c
Doc improvements
mikusaq Sep 27, 2024
917b976
Move buffer size to constant
mikusaq Sep 27, 2024
7b5a097
Error print improvement - overwriting sysroot
mikusaq Sep 27, 2024
566e30f
Add check for existing files in sysroot
mikusaq Sep 27, 2024
8197f03
Refactor check for default port availability
mikusaq Sep 30, 2024
2da225a
Log improvements
mikusaq Sep 30, 2024
d8967c2
More effective cmd line construction of Tar command
mikusaq Sep 30, 2024
32f0db4
Add prerequisites functionality to Tar, add check prerequisites
mikusaq Sep 30, 2024
d8be850
Doc and log improvements
mikusaq Sep 30, 2024
5fa84d9
Add port number to error message
mikusaq Sep 30, 2024
cf1e570
Refactor and optimize Handle function
mikusaq Sep 30, 2024
dee41b3
Remove TODO section from README
mikusaq Sep 30, 2024
509d59b
filepath.Join use
mikusaq Sep 30, 2024
373b705
Doc improvements
mikusaq Sep 30, 2024
9f7353a
Remove not needed error value
mikusaq Oct 1, 2024
c6155c5
Add check for nil
mikusaq Oct 1, 2024
5928ac7
Refactor and optimization
mikusaq Oct 1, 2024
bfdc174
Optimize checking for existing files in sysroot with map
mikusaq Oct 1, 2024
071657f
Add err handling
mikusaq Oct 1, 2024
78b1b22
Refactor
mikusaq Oct 1, 2024
de42ca7
Fix log
mikusaq Oct 1, 2024
1702e30
Infinite loop when circular dependency between packages fix
mikusaq Oct 3, 2024
0a8fdc3
Add check for circular dependencies between packages
mikusaq Oct 3, 2024
6c0dca8
Better error handling
mikusaq Oct 3, 2024
ac09668
Add check for package context directory consistency
mikusaq Oct 3, 2024
1b76148
Change SignalHandlerAddHandler semantics
mikusaq Oct 3, 2024
f31dab3
Address also indirect circular dependencies in check
mikusaq Oct 3, 2024
d5145d6
Merge 'master' into 'BAF-856/packager-update'
mikusaq Oct 3, 2024
531128f
Forced context directory consistency
mikusaq Oct 3, 2024
e2369cf
Move AddHandler to correct location
mikusaq Oct 3, 2024
b55a7d7
Add wait for docker run command when CTRL+C received
mikusaq Oct 3, 2024
b07b8c1
Add CTRL+C handling to PlatformString
mikusaq Oct 3, 2024
d7059de
Typos and documentation
mikusaq Oct 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
go.sum
install_sysroot
localInstall
log
*.zip
128 changes: 67 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,75 @@

# BAP - BringAuto Packager

Build and track C/C++ project dependencies for apps for TODO any Linux distro!
Build and track C/C++ project dependencies for apps on any Linux distro!

BAM - simple way how to build and maintain our dependencies with almost zero learning curve and out-of-the
box integration into our workflows.
BAM provides a simple way to build and maintain dependencies with almost zero learning curve and out-of-the-box integration into your workflows.

## Usage
## Requirements

bap-builder build and stores all dependencies in the git repository
(LFS enabled recommended)
- Docker >= 20.10 (installed according to the official Docker documentation)
- git >= 2.25

1. create git repository (optionally with LFS)
Standalone binaries are built for Linux kernel >= 5.10.0-amd64.

```
mkdir lfsrepo && cd lfsrepo
git init
cd ../
```
## Build

2. Build all docker images needed for build
### Requirements for Build

```
bap-builder build-image --context ./example --name debian11
```
- Go >= 1.22

3. Build all packages for given distro
### Build from Source

Clone the repository and, in the repository root directory, run:

```bash
go get bringauto/bap-builder
cd bap-builder
go build bringauto/bap-builder
```
bap-builder build-package --context ./example --image-name debian11 --output-dir ./lfsrepo --all
```

## Build Standalone Binaries

To build a complete release package, use the `build.sh` script.

Additional requirements for `build.sh`:

- zip
- uname
- sed

## Usage

The `bap-builder` builds and stores all dependencies in the git repository (LFS enabled is recommended).

1. Create a git repository (optionally with LFS):

```bash
mkdir lfsrepo && cd lfsrepo
git init
cd ../
```

2. Build all Docker images needed for the build:

```bash
bap-builder build-image --context ./example --name debian11
```

3. Build all packages for the given distro:

```bash
bap-builder build-package --context ./example --image-name debian11 --output-dir ./lfsrepo --all
```

*Note: If you do not have `bap-builder` in your system path, you need to use `./bap-builder/bap-builder` instead of `bap-builder`.*

## Documentation

The detailed documentation is available in the `doc` directory.

## Example

In the `example` directory, there is a simple example of how to track dependencies for the `example` project.

## Motivation

Expand All @@ -38,7 +78,7 @@ is consistent and work well.
That's really hard to do because every disto has a different version of the same library. If you want to release
you app to a new Linux distro you need to test every dependency, solve bugs, maintain your app in time...

There is no simple way how to track, maintain and pack consistent dependency set for C/C++ project without worrying
There is no simple way how to track, maintain and pack consistent dependency set for C/C++ project without worrying
about different version of libraries, tools and the whole environment.

The needed requirement is
Expand All @@ -54,6 +94,7 @@ If you want to use one of existing solutions (Connan, Nix, ...) to develop relia
In other ways the public repository of the system is not authoritative you cannot rely on the package pushed
to the public repository.\
If you develop a reliable application you need to have authoritative source of the dependencies

- **You need to create your own instance of the system (or pay to someone to host instance for you)**
- **You need to create and push your own packages to obtain authoritative source of dependencies.**

Expand All @@ -70,48 +111,13 @@ BAM solve all these problems! It uses technologies and workflows that are known

You can easily build and track dependencies for your project, download then and use them.

## Requirements

- Docker >= 20.10 (installed by official Docker documentation)
- git >= 2.25

Standalone binaries are built for Linux kernel >= 5.10.0-amd64

## Build

The project requires go >= 1.18.

```
go get bringauto/bap-builder
cd bap-builder
go build bringauto/bap-builder
```

## Build standalone binaries

There is a script `build.sh` by that we can build a complete release package.

Additional requirements for `build.sh`:

- zip
- uname
- sed

## FAQ

### Q: I have got a wierd error

Many errors are caused by problem with SSH connection to the Docker container
or impossibility to start Docker container itself.

In this case

- check if there are no running docker container that
are instance of one of the Docker Images in the context directory
- check if there are no other container that uses port `1122`
### Q: I am encountering a weird error

## TODO
Many errors are caused by issues with the SSH connection to the Docker container or the inability to start the Docker container itself.

- SFTP copy and package creation are too slow (~20 minutes for Boost)
- Refactor `error` handling (use `Log` library, ...) and error messages
In this case:

- Check if there are no running Docker containers that are instances of one of the Docker images in the context directory.
- Check if there are no other containers using port `1122`.
14 changes: 13 additions & 1 deletion bap-builder/CmdArgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ type BuildPackageCmdLineArgs struct {
All *bool
// Name of the package to build (name of the directory in packages/ dir)
Name *string
// BuildDeps Build all dependencies of package when building single package
BuildDeps *bool
// DockerImageName is a name of docker image to which packages will be build.
// If empty all docker images from DockerMatrix in config file are used for a given package.
// If not empty, only packages which contains DockerImageName in DockerMatrix will be built.
// If not empty, packages are built only by toolchain represented by DockerImageName
DockerImageName *string
// OutputDir relative (to program working dir) ot absolute path where the package will be stored
OutputDir *string
// Output dir mode
// OutputDirMode Output dir mode
OutputDirMode *OutputDirMode
}

Expand Down Expand Up @@ -87,6 +89,13 @@ func (cmd *CmdLineArgs) InitFlags() {
Help: "Name of the package to build",
},
)
cmd.BuildPackageArgs.BuildDeps = cmd.buildPackageParser.Flag("", "build-deps",
&argparse.Options{
Required: false,
Default: false,
Help: "Build all dependencies of package when building single package",
},
)
cmd.BuildPackageArgs.OutputDir = cmd.buildPackageParser.String("", "output-dir",
&argparse.Options{
Required: true,
Expand Down Expand Up @@ -134,6 +143,9 @@ func (cmd *CmdLineArgs) ParseArgs(args []string) error {

cmd.BuildImage = cmd.buildImageParser.Happened()
cmd.BuildPackage = cmd.buildPackageParser.Happened()
if *cmd.BuildPackageArgs.All && *cmd.BuildPackageArgs.BuildDeps {
return fmt.Errorf("all and build-deps flags at the same time")
}

return nil
}
72 changes: 67 additions & 5 deletions bap-builder/ContextManager.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"bringauto/modules/bringauto_config"
"fmt"
"io/fs"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -88,6 +88,68 @@ func (context *ContextManager) GetPackageJsonDefPaths(packageName string) ([]str
return packageDefs, nil
}

// getAllDepsJsonPaths
// returns all json defintions paths recursively for given package specified by its json definition path
func (context *ContextManager) getAllDepsJsonPaths(packageJsonPath string, visited map[string]struct{}) ([]string, error) {
var config bringauto_config.Config
err := config.LoadJSONConfig(packageJsonPath)
if err != nil {
return []string{}, fmt.Errorf("couldn't load JSON config from %s path - %s", packageJsonPath, err)
}
visited[packageJsonPath] = struct{}{}
var jsonPathListWithDeps []string
for _, packageDep := range config.DependsOn {
packageDepsJsonPaths, err := context.GetPackageJsonDefPaths(packageDep)
if err != nil {
return []string{}, fmt.Errorf("couldn't get Json Path of %s package", packageDep)
}
var depConfig bringauto_config.Config
for _, packageDepJsonPath := range packageDepsJsonPaths {
_, packageVisited := visited[packageDepJsonPath]
if packageVisited {
continue
}
err := depConfig.LoadJSONConfig(packageDepJsonPath)
if err != nil {
return []string{}, fmt.Errorf("couldn't load JSON config from %s path - %s", packageDepJsonPath, err)
}
if depConfig.Package.IsDebug != config.Package.IsDebug {
continue
}
jsonPathListWithDeps = append(jsonPathListWithDeps, packageDepJsonPath)
jsonPathListWithDepsTmp, err := context.getAllDepsJsonPaths(packageDepJsonPath, visited)
if err != nil {
return []string{}, err
}
jsonPathListWithDeps = append(jsonPathListWithDeps, jsonPathListWithDepsTmp...)
}
}

return jsonPathListWithDeps, nil
}

// GetPackageWithDepsJsonDefPaths
// returns all json definitions paths for given package and all its dependencies json definitions paths recursively
func (context *ContextManager) GetPackageWithDepsJsonDefPaths(packageName string) ([]string, error) {
packageDefs, err := context.GetPackageJsonDefPaths(packageName)
if err != nil {
return []string{}, fmt.Errorf("cannot get config paths for package '%s' - %s", packageName, err)
}
var packageDeps []string
visitedPackages := make(map[string]struct{})
for _, packageDef := range packageDefs {
packageDepsTmp, err := context.getAllDepsJsonPaths(packageDef, visitedPackages)
if err != nil {
return []string{}, err
}
packageDeps = append(packageDeps, packageDepsTmp...)
}

packageDefs = append(packageDefs, packageDeps...)

return packageDefs, nil
}

// GetImageDockerfilePath
// returns Dockerfile path for the given Image locate in the given context
func (context *ContextManager) GetImageDockerfilePath(imageName string) (string, error) {
Expand Down Expand Up @@ -173,17 +235,17 @@ func getAllFilesInSubdirByRegexp(rootDir string, reg *regexp.Regexp) (map[string
// get all files from given rootDir which matches given regexp
func getAllFilesInDirByRegexp(rootDir string, reg *regexp.Regexp) ([]string, error) {
var acceptedFileList []string
fileList, err := ioutil.ReadDir(rootDir)
dirEntryList, err := os.ReadDir(rootDir)
if err != nil {
return []string{}, fmt.Errorf("cannot list dir %s", rootDir)
}

for _, packagesFileInfos := range fileList {
packageNameOk := reg.MatchString(packagesFileInfos.Name())
for _, dirEntry := range dirEntryList {
packageNameOk := reg.MatchString(dirEntry.Name())
if !packageNameOk {
continue
}
acceptedFileList = append(acceptedFileList, path.Join(rootDir, packagesFileInfos.Name()))
acceptedFileList = append(acceptedFileList, path.Join(rootDir, dirEntry.Name()))
}
return acceptedFileList, nil
}
Loading