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

FE-249 add helper scripts to horsefish #178

Merged
merged 9 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
40 changes: 40 additions & 0 deletions .github/workflows/build_and_push_docker_gen_dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Build and Publish Dev Images for scripts/general
on:
push:
branches-ignore: [main]
paths:
- scripts/general/**
- .github/workflows/**
env:
GCP_PROJECT_ID: dsp-fieldeng-dev
GCP_REPOSITORY_GENERAL: horsefish
GITHUB_SHA: ${{ github.sha }}

jobs:
build-and-push-dev-images:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to GCP
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.BASE64_SAKEY_DSPFIELDENG_GARPUSHER }}

- name: Configure Docker to use the Google Artifact Registry
run: gcloud auth configure-docker us-east4-docker.pkg.dev

- name: Build and Push General Docker Image
run: |
docker build -t us-east4-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_REPOSITORY_GENERAL/general_python:$GITHUB_SHA -f scripts/general/Dockerfile scripts/general
docker push us-east4-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_REPOSITORY_GENERAL/general_python:$GITHUB_SHA

- name: Set image tag to 'dev'
run: |
docker tag us-east4-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_REPOSITORY_GENERAL/general_python:$GITHUB_SHA us-east4-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_REPOSITORY_GENERAL/general_python:dev
docker push us-east4-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_REPOSITORY_GENERAL/general_python:dev
43 changes: 43 additions & 0 deletions .github/workflows/build_and_push_docker_gen_main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build and Publish Latest Images for scripts/general
on:
pull_request_target:
types:
- closed
branches:
- main
paths:
- scripts/general/**
- .github/workflows/**
env:
GCP_PROJECT_ID: dsp-fieldeng-dev
GCP_REPOSITORY_GENERAL: horsefish
GITHUB_SHA: ${{ github.sha }}

jobs:
build-and-push-dev-images:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to GCP
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.BASE64_SAKEY_DSPFIELDENG_GARPUSHER }}

- name: Configure Docker to use the Google Artifact Registry
run: gcloud auth configure-docker us-east4-docker.pkg.dev

- name: Build and Push General Docker Image
run: |
docker build -t us-east4-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_REPOSITORY_GENERAL/general_python:$GITHUB_SHA -f scripts/general/Dockerfile scripts/general
docker push us-east4-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_REPOSITORY_GENERAL/general_python:$GITHUB_SHA

- name: Set image tag to 'latest'
run: |
docker tag us-east4-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_REPOSITORY_GENERAL/general_python:$GITHUB_SHA us-east4-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_REPOSITORY_GENERAL/general_python:dev
docker push us-east4-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_REPOSITORY_GENERAL/general_python:latest
8 changes: 8 additions & 0 deletions scripts/general/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM us.gcr.io/broad-dsp-gcr-public/base/python:3.12-alpine

RUN apk add --no-cache bash

COPY find_loop.py /scripts/find_loop.py

ENV PYTHONPATH "/scripts:${PYTHONPATH}"
CMD ["/bin/bash"]
27 changes: 27 additions & 0 deletions scripts/general/find_loop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# loop through the file as a list and search in another file for matching string
# if no match found, print the string


import sys

with open(sys.argv[1]) as f:
lines = [line.strip() for line in f.readlines()]

with open(sys.argv[2], 'r') as f2:
data = f2.read()

for line in lines:
if line in data:
pass
else:
print(f'Not Found: {line}')

# Usage: python find_loop.py file1 file2
# file1: file to loop through
# file2: file to search for matching string
# if no matching string found, print the string
# if found, do nothing
# output: print the string if no matching string found

# Example: You have a list of files in file1 and you want to check if they are present in a json response (file2)
# docker run --rm -v ~bhill/:/bhill us-east4-docker.pkg.dev/dsp-fieldeng-dev/horsefish/general_python:0.2 python3 scripts/find_loop.py /bhill/whattofind.txt /bhill/wheretofind.txt
11 changes: 11 additions & 0 deletions scripts/general/update_gen_py_docker_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This script is used to build and push the general python docker image to the google container registry
# usage: ./update_gen_py_docker_image.sh <version_number>
set -e

VERSION="${1}"
BUILD_TAG="us-east4-docker.pkg.dev/dsp-fieldeng-dev/horsefish/general_python:${VERSION}"

echo "using build tag: ${BUILD_TAG}"

docker build . -t ${BUILD_TAG}
docker push ${BUILD_TAG}
Loading