Skip to content

Commit 4f29dc0

Browse files
authored
Building docker images using GitHub actions (#13)
* add directrunner tests * fix the torch check * split tests * fix test * fix sed * fix path * fix echo * test cat * fix newlines * fix code coverage * add creds to docker.yml * polished sample env * add workflow_dispatch * add workflow_dispatch to pr * update license --------- Co-authored-by: xqhu <xqhu@google.com>
1 parent c31e43a commit 4f29dc0

File tree

9 files changed

+155
-5
lines changed

9 files changed

+155
-5
lines changed

.github/workflows/docker.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2023 Google LLC
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Build and push Docker image to GCP Artifact Registry
16+
17+
on:
18+
workflow_dispatch:
19+
push:
20+
branches:
21+
- main
22+
23+
jobs:
24+
build-and-push:
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v3
30+
- name: Authenticate to Google Cloud
31+
uses: google-github-actions/auth@v1.1.1
32+
with:
33+
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}
34+
token_format: access_token
35+
- name: Docker login -
36+
uses: 'docker/login-action@v1'
37+
with:
38+
registry: 'us-docker.pkg.dev'
39+
username: 'oauth2accesstoken'
40+
password: '${{ steps.auth.outputs.access_token }}'
41+
- name: Init env
42+
run: |
43+
cp tests/sample.env.tf .env
44+
echo '${{ steps.auth.outputs.access_token }}' | docker login -u oauth2accesstoken --password-stdin https://us-docker.pkg.dev
45+
make init
46+
- name: Build and push Docker image
47+
run: |
48+
make docker

.github/workflows/pr.yml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1+
# Copyright 2023 Google LLC
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
name: Run basic tests with Python 3.8
216

3-
on: [push, pull_request]
17+
on: [push, pull_request, workflow_dispatch]
418

519
jobs:
6-
build:
20+
tests:
721

822
runs-on: ubuntu-latest
923

@@ -20,3 +34,20 @@ jobs:
2034
- name: Run local tests
2135
run: |
2236
make test
37+
- name: Run DirectRunner with TF
38+
run: |
39+
# tf model
40+
make run-direct
41+
test -f beam-output/beam_test_out.txt && echo "DirectRunner ran successfully!" || $(error "Cannot find beam-output/beam_test_out.txt!")
42+
- name: Run DirectRunner with PyTorch
43+
run: |
44+
# torch model
45+
sed -i '/TF_MODEL_URI=/d' .env
46+
echo -e "\n" >> .env
47+
echo "MODEL_STATE_DICT_PATH=gs://apache-beam-ml/models/torchvision.models.mobilenet_v2.pth" >> .env
48+
echo -e "\n" >> .env
49+
echo "MODEL_NAME=mobilenet_v2" >> .env
50+
make run-direct
51+
test -f beam-output/beam_test_out.txt && echo "DirectRunner ran successfully!" || $(error "Cannot find beam-output/beam_test_out.txt!")
52+
# restore .env
53+
cp tests/sample.env.tf .env

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ clean: clean-lite ## Remove virtual environment, downloaded models, etc
8080
@echo "run 'make init'"
8181

8282
test: lint ## Run tests
83-
@PYTHONPATH="./:./src" ./venv/bin/pytest -s -vv --cov-config=.coveragerc --cov-report html:htmlcov_v1 --cov-fail-under=50 tests/
83+
@PYTHONPATH="./:./src" ./venv/bin/pytest -s -vv --cov=src --cov-fail-under=50 tests/
8484

8585
run-direct: ## Run a local test with DirectRunner
86+
@rm -f beam-output/beam_test_out.txt
8687
ifeq ($(MODEL_ENV), "TORCH")
8788
time ./venv/bin/python3 -m src.run \
8889
--input data/openimage_10.txt \

scripts/check-beam.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
#!/bin/bash
22

3+
# Copyright 2023 Google LLC
4+
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
317
# Import environment variables from .env file.
418
source .env
519

scripts/check-pipeline.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
#!/bin/bash
22

3+
# Copyright 2023 Google LLC
4+
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
317
# Import environment variables from .env file.
418
source .env
519

scripts/check-tf-on-gpu.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
#!/bin/bash
22

3+
# Copyright 2023 Google LLC
4+
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
317
# Import environment variables from .env file.
418
source .env
519

scripts/check-torch-on-gpu.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
#!/bin/bash
22

3+
# Copyright 2023 Google LLC
4+
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
317
# Import environment variables from .env file.
418
source .env
519

scripts/create-gpu-vm.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
#!/bin/bash
22

3+
# Copyright 2023 Google LLC
4+
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
317
# Import environment variables from .env file.
418
source .env
519

tests/sample.env.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ VM_NAME=beam-ml-starter-gpu
1919
################################################################################
2020
STAGING_LOCATION=gs://temp-storage-for-perf-tests/loadtests
2121
TEMP_LOCATION=gs://temp-storage-for-perf-tests/loadtests
22-
CUSTOM_CONTAINER_IMAGE=us-docker.pkg.dev/apache-beam-testing/xqhu/tf_gpu:test
22+
CUSTOM_CONTAINER_IMAGE=us-docker.pkg.dev/apache-beam-testing/dataflow-ml-starter/tf_gpu:test
2323
SERVICE_OPTIONS="worker_accelerator=type:nvidia-tesla-t4;count:1;install-nvidia-driver"
2424
################################################################################
2525
### DATAFLOW JOB MODEL SETTINGS
@@ -30,4 +30,4 @@ TF_MODEL_URI=https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/4
3030
### DATAFLOW JOB INPUT&OUTPUT SETTINGS
3131
################################################################################
3232
INPUT_DATA="gs://apache-beam-ml/testing/inputs/openimage_50k_benchmark.txt"
33-
OUTPUT_DATA="gs://temp-storage-for-end-to-end-tests/torch/result_gpu_xqhu.txt"
33+
OUTPUT_DATA="gs://temp-storage-for-end-to-end-tests/temp-storage-for-end-to-end-tests/dataflow-ml-starter/result_gpu.txt"

0 commit comments

Comments
 (0)