Skip to content

Commit

Permalink
added platforms for linux packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
oakrizan committed Jan 27, 2024
1 parent a8490fc commit 243e961
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .buildkite/env-scripts/linux-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ DEBIAN_FRONTEND="noninteractive"

export DEBIAN_FRONTEND

sudo mkdir -p /etc/needrestart
echo "\$nrconf{restart} = 'a';" | sudo tee -a /etc/needrestart/needrestart.conf > /dev/null

# Remove this code once beats specific agent is set up
if [[ $PLATFORM_TYPE == "Linux" ]]; then
echo ":: Installing libs ::"
Expand Down
3 changes: 3 additions & 0 deletions .buildkite/filebeat/filebeat-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ steps:
agents:
provider: "gcp"
image: "${IMAGE_UBUNTU_X86_64}"
machineType: "c2-standard-16"
artifact_paths:
- "filebeat/build/*.xml"
- "filebeat/build/*.json"
Expand All @@ -36,6 +37,7 @@ steps:
agents:
provider: "gcp"
image: "${IMAGE_UBUNTU_X86_64}"
machineType: "c2-standard-16"
artifact_paths:
- "filebeat/build/*.xml"
- "filebeat/build/*.json"
Expand All @@ -49,6 +51,7 @@ steps:
agents:
provider: "gcp"
image: "${IMAGE_UBUNTU_X86_64}"
machineType: "c2-standard-16"
artifact_paths:
- "filebeat/build/*.xml"
- "filebeat/build/*.json"
Expand Down
2 changes: 2 additions & 0 deletions .buildkite/filebeat/scripts/package-step.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ if are_files_changed "$changeset"; then
steps:
- label: ":ubuntu: Packaging Linux X86"
key: "package-linux-x86"
env:
PLATFORMS: "+all linux/amd64 linux/arm64 windows/amd64 darwin/amd64 darwin/arm64"
command:
- ".buildkite/filebeat/scripts/package.sh"
notify:
Expand Down
37 changes: 15 additions & 22 deletions dev-tools/packaging/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func checkNpcapNotices(pkg, file string, contents io.Reader) error {
}

func checkDocker(t *testing.T, file string) {
p, info, err := readDocker(file)
p, info, err := readDockerNew(file)
if err != nil {
t.Errorf("error reading file %v: %v", file, err)
return
Expand Down Expand Up @@ -713,10 +713,12 @@ func readZip(t *testing.T, zipFile string, inspectors ...inspector) (*packageFil
return p, nil
}

func readDocker(dockerFile string) (*packageFile, *dockerInfo, error) {
// Read the manifest file first so that the config file and layer
// names are known in advance.
manifest, err := getDockerManifest(dockerFile)
func readDockerNew(dockerFile string) (*packageFile, *dockerInfo, error) {
var manifest *dockerManifest
var info *dockerInfo
layers := make(map[string]*packageFile)

manifest, err := readManifest(dockerFile)
if err != nil {
return nil, nil, err
}
Expand All @@ -727,9 +729,6 @@ func readDocker(dockerFile string) (*packageFile, *dockerInfo, error) {
}
defer file.Close()

var info *dockerInfo
layers := make(map[string]*packageFile)

gzipReader, err := gzip.NewReader(file)
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -770,11 +769,7 @@ func readDocker(dockerFile string) (*packageFile, *dockerInfo, error) {

// Read layers in order and for each file keep only the entry seen in the later layer
p := &packageFile{Name: filepath.Base(dockerFile), Contents: map[string]packageEntry{}}
for _, layer := range manifest.Layers {
layerFile, found := layers[layer]
if !found {
return nil, nil, fmt.Errorf("layer not found: %s", layer)
}
for _, layerFile := range layers {
for name, entry := range layerFile.Contents {
// Check only files in working dir and entrypoint
if strings.HasPrefix("/"+name, workingDir) || "/"+name == entrypoint {
Expand All @@ -799,22 +794,21 @@ func readDocker(dockerFile string) (*packageFile, *dockerInfo, error) {
return p, info, nil
}

// getDockerManifest opens a gzipped tar file to read the Docker manifest.json
// that it is expected to contain.
func getDockerManifest(file string) (*dockerManifest, error) {
f, err := os.Open(file)
func readManifest(dockerFile string) (*dockerManifest, error) {
var manifest *dockerManifest

file, err := os.Open(dockerFile)
if err != nil {
return nil, err
}
defer f.Close()
defer file.Close()

gzipReader, err := gzip.NewReader(f)
gzipReader, err := gzip.NewReader(file)
if err != nil {
return nil, err
}
defer gzipReader.Close()

var manifest *dockerManifest
tarReader := tar.NewReader(gzipReader)
for {
header, err := tarReader.Next()
Expand All @@ -833,8 +827,7 @@ func getDockerManifest(file string) (*dockerManifest, error) {
break
}
}

return manifest, nil
return manifest, err
}

type dockerManifest struct {
Expand Down

0 comments on commit 243e961

Please sign in to comment.