Skip to content

Continuous Monitoring of Dockerhub and public ECR #17233

Continuous Monitoring of Dockerhub and public ECR

Continuous Monitoring of Dockerhub and public ECR #17233

name: Continuous Monitoring of Dockerhub and public ECR
on:
workflow_dispatch:
schedule:
- cron: '*/10 * * * *'
jobs:
monitor-ecr:
name: Monitor public ECR
runs-on: ubuntu-latest
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_TEST_ACCOUNT }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_TEST_ACCOUNT }}
aws-region: us-east-1
- name: Login to Public ECR
uses: docker/login-action@v1
with:
registry: public.ecr.aws
- name: Pull an image from public ECR
id: pull-from-ecr
run: docker pull public.ecr.aws/xray/aws-xray-daemon:latest
- name: Publish metric on pulling an image
if: ${{ always() }}
run: |
if [[ "${{ steps.pull-from-ecr.outcome }}" == "failure" ]]; then
aws cloudwatch put-metric-data --metric-name PullImageFailureFromECR --dimensions failure=rate --namespace MonitorDaemon --value 1 --timestamp $(date +%s)
else
aws cloudwatch put-metric-data --metric-name PullImageFailureFromECR --dimensions failure=rate --namespace MonitorDaemon --value 0 --timestamp $(date +%s)
fi
- name: Run daemon image
run: |
docker run --name xray-daemon public.ecr.aws/xray/aws-xray-daemon:latest -o -n us-west-2 &
sleep 30
- name: Publish metrics on daemon startup
if: ${{ always() }}
run: |
if [[ "$(docker container inspect -f '{{.State.Status}}' xray-daemon )" != "running" ]]; then
aws cloudwatch put-metric-data --metric-name DaemonImageStartupFailureFromECR --dimensions failure=rate --namespace MonitorDaemon --value 1 --timestamp $(date +%s)
else
aws cloudwatch put-metric-data --metric-name DaemonImageStartupFailureFromECR --dimensions failure=rate --namespace MonitorDaemon --value 0 --timestamp $(date +%s)
fi
monitor-dockerhub:
name: Monitor docker hub
runs-on: ubuntu-latest
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_TEST_ACCOUNT }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_TEST_ACCOUNT }}
aws-region: us-east-1
- name: Pull an image from docker hub
id: pull-from-dockerhub
run: docker pull amazon/aws-xray-daemon:latest
- name: Publish metric on pulling an image
if: ${{ always() }}
run: |
if [[ "${{ steps.pull-from-dockerhub.outcome }}" == "failure" ]]; then
aws cloudwatch put-metric-data --metric-name PullImageFailureFromDockerhub --dimensions failure=rate --namespace MonitorDaemon --value 1 --timestamp $(date +%s)
else
aws cloudwatch put-metric-data --metric-name PullImageFailureFromDockerhub --dimensions failure=rate --namespace MonitorDaemon --value 0 --timestamp $(date +%s)
fi
- name: Run daemon image
run: |
docker run --name xray-daemon amazon/aws-xray-daemon:latest -o -n us-west-2 &
sleep 30
- name: Publish metrics on daemon startup
if: ${{ always() }}
run: |
if [[ "$(docker container inspect -f '{{.State.Status}}' xray-daemon )" != "running" ]]; then
aws cloudwatch put-metric-data --metric-name DaemonImageStartupFailureFromDockerhub --dimensions failure=rate --namespace MonitorDaemon --value 1 --timestamp $(date +%s)
else
aws cloudwatch put-metric-data --metric-name DaemonImageStartupFailureFromDockerhub --dimensions failure=rate --namespace MonitorDaemon --value 0 --timestamp $(date +%s)
fi