Merge pull request #16 from fetchoracle/update-readme #5
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: 'Image Builder' | |
on: | |
push: | |
tags: | |
- 'v*' | |
branches: | |
- main | |
- dev | |
permissions: | |
contents: read | |
env: | |
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
TOKEN_GITHUB: ${{ secrets.TOKEN_GITHUB }} | |
jobs: | |
test: | |
name: 'Tests' | |
runs-on: ubuntu-latest | |
env: | |
working-directory: ${{ github.workspace }} | |
defaults: | |
run: | |
shell: bash | |
working-directory: ${{ env.working-directory }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.ref_name }} | |
submodules: true | |
token: ${{ secrets.TOKEN_GITHUB }} | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.9 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: 16 | |
- name: Install Dependencies | |
run: | | |
mv ./telliot-core ../ | |
pip install --no-cache-dir -r requirements.txt && pip install -e . | |
cd ../telliot-core && pip install --no-cache-dir -r requirements-dev.txt && pip install -e . | |
npm install -g ganache | |
# - name: Run tests | |
# run: pytest | |
- name: Obtain Commit SHA | |
if: always() | |
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV | |
- name: Send Slack Notification | |
uses: slackapi/slack-github-action@v1.19.0 | |
if: always() | |
with: | |
channel-id: 'devops-build-notification' | |
payload: | | |
{ | |
"blocks": [ | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": "GitHub Action ${{github.repository}} result: *${{ job.status }}*" | |
} | |
}, | |
{ | |
"type": "section", | |
"fields": [ | |
{ | |
"type": "mrkdwn", | |
"text": "*REPO:*\n${{github.repository}}" | |
}, | |
{ | |
"type": "mrkdwn", | |
"text": "*JOB NAME:*\nTest telliot-feeds" | |
}, | |
{ | |
"type": "mrkdwn", | |
"text": "*COMMIT:*\n<${{ github.event.pull_request.html_url || github.event.head_commit.url }}|${{env.SHORT_SHA}}>" | |
}, | |
{ | |
"type": "mrkdwn", | |
"text": "*Author:*\n${{github.actor}}" | |
} | |
] | |
} | |
] | |
} | |
publish: | |
name: 'Image Builder' | |
runs-on: ubuntu-latest | |
# needs: test | |
if: startsWith(github.ref, 'refs/tags/v') | |
env: | |
working-directory: ${{ github.workspace }} | |
defaults: | |
run: | |
shell: bash | |
working-directory: ${{ env.working-directory }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.ref_name }} | |
submodules: true | |
token: ${{ secrets.TOKEN_GITHUB }} | |
- name: Add profile credentials to ~/.aws/credentials | |
run: | | |
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }} --profile fetchoracle-dev | |
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }} --profile fetchoracle-dev | |
- name: Build Image | |
run: docker buildx build --platform=linux/amd64 -t telliot-reporters . --no-cache | |
- name: Publish Image to ECR | |
id: ecr | |
run: | | |
TAG=${{ github.ref }} | |
TAG=${TAG#refs/tags/} | |
echo "Tag value: $TAG" | |
aws ecr get-login-password --region ap-southeast-2 --profile fetchoracle-dev | docker login --username AWS --password-stdin 090838539286.dkr.ecr.ap-southeast-2.amazonaws.com | |
docker tag telliot-reporters:latest 090838539286.dkr.ecr.ap-southeast-2.amazonaws.com/telliot-reporters:$TAG | |
docker push 090838539286.dkr.ecr.ap-southeast-2.amazonaws.com/telliot-reporters:$TAG | |
echo "::set-output name=reporters_image_uri::090838539286.dkr.ecr.ap-southeast-2.amazonaws.com/telliot-reporters:$TAG" | |
- name: Git-Repo-Checkout | |
uses: actions/checkout@v3 | |
with: | |
repository: "fetchoracle/IaC" | |
ref: ${{ github.ref_name }} | |
fetch-depth: 0 | |
path: IaC | |
token: ${{ secrets.TOKEN_GITHUB }} | |
persist-credentials: true | |
- name: Pull latest changes from the remote branch | |
shell: bash | |
working-directory: "IaC" | |
run: | | |
git pull origin ${{ github.ref_name }} | |
- name: Update Image Tag in Terraform Vars | |
shell: bash | |
working-directory: "IaC" | |
run: | | |
cd reporters/${{ github.ref_name }} | |
IMAGE_URI=${{ steps.ecr.outputs.reporters_image_uri }} | |
sed -i "6s/.*/image_tag = \"${IMAGE_URI}\"/" ${{ github.ref_name }}.tfvars | |
- name: Commit and Push Changes | |
shell: bash | |
working-directory: "IaC" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git add reporters/${{ github.ref_name }}/${{ github.ref_name }}.tfvars | |
git commit -m "Update image tag to ${{ steps.ecr.outputs.reporters_image_uri }}" | |
git push origin ${{ github.ref_name }} | |
- name: Obtain Commit SHA | |
if: always() | |
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV | |
- name: Send Slack Notification | |
uses: slackapi/slack-github-action@v1.19.0 | |
if: always() | |
with: | |
channel-id: 'devops-build-notification' | |
payload: | | |
{ | |
"blocks": [ | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": "GitHub Action ${{github.repository}} result: *${{ job.status }}*" | |
} | |
}, | |
{ | |
"type": "section", | |
"fields": [ | |
{ | |
"type": "mrkdwn", | |
"text": "*REPO:*\n${{github.repository}}" | |
}, | |
{ | |
"type": "mrkdwn", | |
"text": "*JOB NAME:*\nPublish Image" | |
}, | |
{ | |
"type": "mrkdwn", | |
"text": "*COMMIT:*\n<${{ github.event.pull_request.html_url || github.event.head_commit.url }}|${{env.SHORT_SHA}}>" | |
}, | |
{ | |
"type": "mrkdwn", | |
"text": "*Author:*\n${{github.actor}}" | |
} | |
] | |
} | |
] | |
} |