Basic Dockerfile template #89
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Flyte Integration Suite | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build_images: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
tags: true | |
token: ${{ secrets.FLYTE_BOT_PAT }} | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ secrets.FLYTE_BOT_USERNAME }} | |
password: ${{ secrets.FLYTE_BOT_PAT }} | |
- name: Iterate through top level directories and build Docker images | |
env: | |
ACCESS_TOKEN: ${{ secrets.FLYTE_BOT_PAT }} | |
run: | | |
# Get the SHA of the base commit of the PR | |
base_sha=${{ github.event.pull_request.base.sha }} | |
special_tag=build-success-${{github.event.pull_request.number}} | |
# Get the list of changed files between the last commit and the current one | |
latest_tag=$(git tag -l $special_tag | sort -V | tail -n 1) | |
if [ -z "$latest_tag" ]; then | |
echo "no previous successful build tag exists" | |
# If no previous successful build tag exists, check all commits | |
changed_files=$(git diff --name-only $base_sha HEAD) | |
else | |
# Otherwise, check only the commits since the last successful build | |
echo "previous successful build tag exists" | |
changed_files=$(git diff --name-only $latest_tag HEAD) | |
fi | |
echo "Changed files: $changed_files" | |
for dir in *; do | |
if [ -f "$dir/{{cookiecutter.project_name}}/Dockerfile" ]; then | |
# Check if any of the changed files are in the current directory | |
if echo "$changed_files" | grep -q "^$dir/"; then | |
echo "Building and pushing Docker image for $dir" | |
docker build -f $dir/{{cookiecutter.project_name}}/Dockerfile -t ghcr.io/${{ github.repository }}:${dir}-pr-${{github.event.pull_request.number}} $dir/{{cookiecutter.project_name}} | |
docker push ghcr.io/${{ github.repository }}:${dir}-pr-${{github.event.pull_request.number}} | |
else | |
echo "Skipping $dir as it does not contain changes" | |
fi | |
else | |
echo "Skipping $dir as it does not contain a Dockerfile" | |
fi | |
done | |
if [ -z "$latest_tag" ]; then | |
echo "No previous successful build tag exists, so no need to delete it" | |
else | |
echo "Deleting last tag and replacing it with this one, since it was successful" | |
git tag -d $latest_tag | |
git push origin :refs/tags/$latest_tag | |
fi | |
git config user.name "GitHub Actions" | |
git config user.email "[email protected]" | |
git tag build-success-${{ github.event.pull_request.number }} HEAD | |
git push origin build-success-${{ github.event.pull_request.number }} | |
integration_tests: | |
needs: build_images | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v2 | |
- name: Run integration tests | |
env: | |
host: ${{ secrets.FLYTE_HOST }} | |
client_id: ${{ secrets.FLYTE_CLIENT_ID }} | |
client_secret: ${{ secrets.FLYTE_CLIENT_SECRET }} | |
run: | | |
pip install -r requirements.txt | |
python integration.py \ | |
--host $host \ | |
--client_id $client_id \ | |
--client_secret $client_secret \ | |
--image_suffix pr-${{ github.event.pull_request.number }} \ | |
--image_hostname ghcr.io/${{ github.repository }} |