Commit c8b70289 authored by Harrison Saturley-Hall's avatar Harrison Saturley-Hall Committed by GitHub
Browse files

ci: start using ECR for container caches (#77)

parent 07afe3c9
...@@ -35,40 +35,45 @@ jobs: ...@@ -35,40 +35,45 @@ jobs:
name: Build and Test - ${{ matrix.framework }} name: Build and Test - ${{ matrix.framework }}
env: env:
CONTAINER_ID: test_${{ github.run_id }}_${{ github.run_attempt }}_${{ github.job }}_${{ matrix.framework }} CONTAINER_ID: test_${{ github.run_id }}_${{ github.run_attempt }}_${{ github.job }}_${{ matrix.framework }}
IMAGE_TAG: ghcr.io/${{ github.repository }}:latest-${{ matrix.framework }}
PYTEST_XML_FILE: pytest_test_report.xml PYTEST_XML_FILE: pytest_test_report.xml
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry - name: Configure AWS credentials
uses: docker/login-action@v3 uses: aws-actions/configure-aws-credentials@v4
with: with:
registry: ghcr.io aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
username: ${{ github.actor }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
password: ${{ secrets.GITHUB_TOKEN }} aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Define Image Tag
id: define_image_tag
run: |
echo "image_tag=${{ steps.login-ecr.outputs.registry }}/${{ github.repository }}:latest-${{ matrix.framework }}" >> $GITHUB_OUTPUT
- name: Decide on cache - name: Decide on cache
id: which_caches id: which_caches
run: | run: |
set +e set +e
if [ "${{ github.event_name }}" == "pull_request" ]; then if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "Not pushing to container image cache" echo "Not pushing to container image cache"
echo "cache_to_location=" >> $GITHUB_OUTPUT echo "cache_to_location=" >> $GITHUB_OUTPUT
else else
echo "Pushing ${{ env.IMAGE_TAG }} to container image cache" echo "Pushing ${{ steps.define_image_tag.outputs.image_tag }} to container image cache"
echo "cache_to_location=--cache-to \"type=registry,ref=${{ env.IMAGE_TAG }},image-manifest=true,mode=max\"" >> $GITHUB_OUTPUT echo "cache_to_location=--cache-to \"type=registry,ref=${{ steps.define_image_tag.outputs.image_tag }},image-manifest=true,mode=max\"" >> $GITHUB_OUTPUT
fi fi
echo "cache_from_location=--cache-from \"type=registry,ref=${{ env.IMAGE_TAG }}\"" >> $GITHUB_OUTPUT echo "cache_from_location=--cache-from \"type=registry,ref=${{ steps.define_image_tag.outputs.image_tag }}\"" >> $GITHUB_OUTPUT
- name: Build image - name: Build image
run: | run: |
./container/build.sh --tag ${{ env.IMAGE_TAG }} --framework ${{ matrix.framework }} ${{ steps.which_caches.outputs.cache_from_location }} ${{ steps.which_caches.outputs.cache_to_location }} ./container/build.sh --tag ${{ steps.define_image_tag.outputs.image_tag }} --framework ${{ matrix.framework }} ${{ steps.which_caches.outputs.cache_from_location }} ${{ steps.which_caches.outputs.cache_to_location }}
- name: Run pytest - name: Run pytest
env: env:
PYTEST_MARKS: "pre_merge or mypy" PYTEST_MARKS: "pre_merge or mypy"
run: | run: |
docker run -w /workspace --name ${{ env.CONTAINER_ID }} ${{ env.IMAGE_TAG }} pytest --basetemp=/tmp --junitxml=${{ env.PYTEST_XML_FILE }} -m "${{ env.PYTEST_MARKS }}" docker run -w /workspace --name ${{ env.CONTAINER_ID }} ${{ steps.define_image_tag.outputs.image_tag }} pytest --basetemp=/tmp --junitxml=${{ env.PYTEST_XML_FILE }} -m "${{ env.PYTEST_MARKS }}"
- name: Copy test report from test Container - name: Copy test report from test Container
if: always() if: always()
run: | run: |
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment