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

Add docker files and pipeline #2

Merged
merged 9 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
59 changes: 59 additions & 0 deletions .github/workflows/build_elastic_common_schema_toolchain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Build ECS Toolchain Image
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::068738303278:role/PushPullECSToolchainImage
aws-region: us-east-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

# Setting up Docker Buildx with docker-container driver is required
# Setting up Docker Buildx with docker-container driver is required
# at the moment to be able to use a subdirectory with Git context
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Debug
run: 'echo Branch name: "${{ github.head_ref || github.ref_name }}"'

# Always push with the branch name, this allows for external testing
- name: Build and Push
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:docker"
tags: 068738303278.dkr.ecr.us-east-1.amazonaws.com/elastic-common-schema-toolchain:${{ github.head_ref || github.ref_name }}
cache-from: type=registry,ref=068738303278.dkr.ecr.us-east-1.amazonaws.com/elastic-common-schema-toolchain:cache
cache-to: mode=max,image-manifest=true,oci-mediatypes=true,type=registry,ref=068738303278.dkr.ecr.us-east-1.amazonaws.com/elastic-common-schema-toolchain:cache
push: true
build-args: |
BRANCH=${{ github.head_ref || github.ref_name }}

# Once it's in main, we want to update to the latest stable version
- name: Push Latest Tag
if: github.ref_name == 'main'
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:docker"
tags: 068738303278.dkr.ecr.us-east-1.amazonaws.com/elastic-common-schema-toolchain:latest
cache-from: type=registry,ref=068738303278.dkr.ecr.us-east-1.amazonaws.com/elastic-common-schema-toolchain:cache
cache-to: mode=max,image-manifest=true,oci-mediatypes=true,type=registry,ref=068738303278.dkr.ecr.us-east-1.amazonaws.com/elastic-common-schema-toolchain:cache
push: true
build-args: |
BRANCH=${{ github.ref_name }}
7 changes: 7 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM ubuntu:latest
ARG BRANCH=main
RUN mkdir /ecs && apt update && apt install -y git python3-pip && apt clean
WORKDIR /ecs
RUN git clone https://github.com/huntresslabs/ecs . && git checkout ${BRANCH} && python3 -m pip install --break-system-packages -r scripts/requirements.txt
COPY scripts/entry_point.sh entry_point.sh
ENTRYPOINT ["/bin/bash", "/ecs/entry_point.sh"]
23 changes: 23 additions & 0 deletions docker/scripts/entry_point.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

python3 scripts/generator.py --subset /data_stream/subset --out /data_stream --include /include /data_stream/include
code=$?
if [ $code -ne 0 ]; then
exit $code
fi

# Moving this functionality into the ECS tool
# for yaml_file in $(find {"/include","/data_stream/include"} -name '*.yml' -type f); do
# file_name="${yaml_file##*/}"
# if [ "$(yq '.0 | has("settings")' $yaml_file)" == "true" ]; then
# out_file="/data_stream/generated/elasticsearch/composable/component/${file_name%.yml}.json"
# echo "Adding settings from ${file_name} to ${out_file##*/}"
# yq '.0.settings' -o json $yaml_file | jq '.tmp.template.settings = .' | jq '.tmp' > /tmp/settings.json
# jq -s '.[0] * .[1]' $out_file /tmp/settings.json > /tmp/combined.json
# mv /tmp/combined.json $out_file
# else
# echo "$file_name does NOT have settings"
# fi
# done
echo "Opening permissions"
chmod -R 'u=rwX,g=rwX,o=rwX' "/data_stream/generated"
Loading