-
Notifications
You must be signed in to change notification settings - Fork 5
159 lines (137 loc) · 6.53 KB
/
docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: docker-build
on:
workflow_dispatch:
pull_request:
branches:
- main
- develop
push:
branches:
- main
- develop
tags:
- 'v*'
env:
TERRAFORM_REPO: 'terra-money/tf-terra-oracle'
jobs:
refs-parsing:
runs-on: ubuntu-latest
outputs:
oracle_address: ${{ steps.parse-refs.outputs.oracle_address }}
price_server_port: ${{ steps.parse-refs.outputs.price_server_port }}
feeder_retries: ${{ steps.parse-refs.outputs.feeder_retries }}
alliance_hub_contract_address: ${{ steps.parse-refs.outputs.alliance_hub_contract_address }}
blocks_to_be_senior_validator: ${{ steps.parse-refs.outputs.blocks_to_be_senior_validator }}
vote_on_proposals_to_be_senior_validator: ${{ steps.parse-refs.outputs.vote_on_proposals_to_be_senior_validator }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Parse refs.json
id: parse-refs
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
run: |
# Install jq to parse JSON
sudo apt-get update
sudo apt-get install -y jq
# Determine the branch name
BRANCH_NAME=${GITHUB_REF#refs/heads/}
# Parse params.json and extract the required information
ORACLE_ADDRESS=$(jq -r --arg branch "$BRANCH_NAME" '.[$branch].oracle_address' params.json)
ALLIANCE_HUB_CONTRACT_ADDRESS=$(jq -r --arg branch "$BRANCH_NAME" '.[$branch].alliance_hub_contract_address' params.json)
PRICE_SERVER_PORT=$(jq -r --arg branch "$BRANCH_NAME" '.[$branch].price_server_port' params.json)
FEEDER_RETRIES=$(jq -r --arg branch "$BRANCH_NAME" '.[$branch].feeder_retries' params.json)
BLOCKS_TO_BE_SENIOR_VALIDATOR=$(jq -r --arg branch "$BRANCH_NAME" '.[$branch].blocks_to_be_senior_validator' params.json)
VOTE_ON_PROPOSALS_TO_BE_SENIOR_VALIDATOR=$(jq -r --arg branch "$BRANCH_NAME" '.[$branch].vote_on_proposals_to_be_senior_validator' params.json)
# Set output parameters for subsequent jobs
echo "::set-output name=oracle_address::$ORACLE_ADDRESS"
echo "::set-output name=alliance_hub_contract_address::$ALLIANCE_HUB_CONTRACT_ADDRESS"
echo "::set-output name=price_server_port::$PRICE_SERVER_PORT"
echo "::set-output name=feeder_retries::$FEEDER_RETRIES"
echo "::set-output name=blocks_to_be_senior_validator::$BLOCKS_TO_BE_SENIOR_VALIDATOR"
echo "::set-output name=vote_on_proposals_to_be_senior_validator::$VOTE_ON_PROPOSALS_TO_BE_SENIOR_VALIDATOR"
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v3
# https://docs.docker.com/build/ci/github-actions/multi-platform/
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
- name: Log in to the github container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ap-northeast-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
images: |
ghcr.io/${{ github.repository }}
${{ steps.login-ecr.outputs.registry }}/${{ github.event.repository.name }}
tags: |
type=sha
type=edge,branch=develop
type=semver,pattern={{tag}}
type=semver,pattern={{version}}
type=raw,value=latest,event=branch,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=main,event=branch,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=develop,event=branch,enable=${{ github.ref == format('refs/heads/{0}', 'develop') }}
- name: Build docker image
uses: docker/build-push-action@v3
with:
push: ${{ github.event_name != 'pull_request' }}
file: Dockerfile
platforms: linux/amd64
# platforms: linux/amd64,linux/arm64
tags: ${{ env.DOCKER_METADATA_OUTPUT_TAGS }}
labels: ${{ env.DOCKER_METADATA_OUTPUT_LABELS }}
dispatch:
runs-on: ubuntu-latest
needs: [build, refs-parsing]
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
steps:
- name: Set Remote ref
run: |
if [ ${GITHUB_REF} == "refs/heads/main" ]; then
echo "TF_GITHUB_REF=phoenix-1" >> $GITHUB_ENV
echo "TAG=main" >> $GITHUB_ENV
elif [ ${GITHUB_REF} == "refs/heads/develop" ]; then
echo "TF_GITHUB_REF=pisco-1" >> $GITHUB_ENV
echo "TAG=develop" >> $GITHUB_ENV
fi
- name: Check variables
run: |
if [[ ! "${{ needs.refs-parsing.outputs.oracle_address }}" =~ ^terra ]]; then
echo "ORACLE_ADDRESS does not start with 'terra'"
exit 1
fi
if [[ ! "${{ needs.refs-parsing.outputs.alliance_hub_contract_address }}" =~ ^terra ]]; then
echo "ALLIANCE_HUB_CONTRACT_ADDRESS does not start with 'terra'"
exit 1
fi
- name: Invoke Terraform Workflow
uses: aurelien-baudet/workflow-dispatch@v2
with:
repo: ${{ env.TERRAFORM_REPO }}
ref: ${{ env.TF_GITHUB_REF }}
workflow: Terraform
token: ${{ secrets.TFL_GITHUB_TOKEN }}
inputs: '{ "ALLIANCE_HUB_CONTRACT_ADDRESS": "${{ needs.refs-parsing.outputs.alliance_hub_contract_address }}","BLOCKS_TO_BE_SENIOR_VALIDATOR": "${{ needs.refs-parsing.outputs.blocks_to_be_senior_validator }}","VOTE_ON_PROPOSALS_TO_BE_SENIOR_VALIDATOR": "${{ needs.refs-parsing.outputs.vote_on_proposals_to_be_senior_validator }}", "ORACLE_ADDRESS": "${{ needs.refs-parsing.outputs.oracle_address }}", "PRICE_SERVER_PORT": "${{needs.refs-parsing.outputs.price_server_port}}", "FEEDER_RETRIES": "${{needs.refs-parsing.outputs.feeder_retries}}", "TAG": "${{env.TAG}}" }'