-
Notifications
You must be signed in to change notification settings - Fork 182
161 lines (147 loc) · 5.78 KB
/
image-build.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
160
161
name: image-builder
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to build'
required: false
tag:
description: 'Tag to build'
required: false
type:
description: 'Image type to build, eg: val, explorer'
required: false
default: 'explorer'
type: choice
options:
- rpc
- cli
- public_full
- val
- explorer
network:
description: 'Network type, eg: mainnet, testnet'
required: false
default: 'mainnet'
type: choice
options:
- mainnet
- testnet
base_env:
description: 'Base environment, eg: mainnet-> go1.20.1-static-v102-8d2c621, testnet -> go1.20.1-static-v136-ec580bc'
required: false
default: 'go1.20.1-static-v102-8d2c621'
innertx:
description: 'go-ethereum innertx version, eg: v1.10.8'
required: false
default: 'innerTx-1.10.08'
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch || github.event.inputs.tag }}
token: ${{ secrets.TOKEN }}
- name: Script and Generate Dockerfile
run: |
git config --global url.https://${{ secrets.TOKEN }}@github.com/.insteadOf https://github.com/
git config --global user.email "github_action@example.com"
git config --global user.name "Github Action"
long_commit_id=$(git rev-parse HEAD)
branch=${{ github.event.inputs.branch }}
tag=${{ github.event.inputs.tag }}
if [ -z "$branch" ] && [ -z "$tag" ]; then
echo "Both branch and tag are empty."
exit 1
elif [ -n "$branch" ] && [ -n "$tag" ]; then
echo "Both branch and tag are provided. Please provide only one."
exit 1
else
echo "Correct! One of branch or tag is provided."
fi
type=${{ github.event.inputs.type }}
network=${{ github.event.inputs.network }}
base_env=""
if [ "$network" = "mainnet" ]; then
base_env="go1.20.1-static-v102-8d2c621"
elif [ "$network" = "testnet" ]; then
base_env="go1.20.1-static-v136-ec580bc"
fi
innertx=${{ github.event.inputs.innertx }}
echo "========== params:==========="
echo "type: $type"
echo "network: $network"
echo "base_env: $base_env"
echo "innertx: $innertx"
echo "long_commit_id: $long_commit_id"
echo "========== params end==========="
if [ "$type" = "val" ]; then
git clone https://github.com/okx/okexchain-patches.git
cd ./okexchain-patches
git checkout main
cd ..
git rev-parse HEAD
git am ./okexchain-patches/priorQueue/*.patch
echo '打prior_tx后ID:'$(git rev-parse HEAD)
rm -rf ./okexchain-patches
elif [ "$type" = "explorer" ]; then
git clone https://github.com/okx/okexchain-patches.git
cd ./okexchain-patches
git checkout fcb6da71610a6c20a9e13bffcbc3623b86c4c09e
git rev-parse HEAD
cd ..
git clone https://github.com/okx/go-ethereum-innertx.git go-ethereum
cd ./go-ethereum
git checkout "$innertx"
git rev-parse HEAD
cd ..
git am ./okexchain-patches/innerTx/*.patch
echo '打补丁浏览器补丁后ID:'$(git rev-parse HEAD)
go mod edit -replace github.com/ethereum/go-ethereum=./go-ethereum
rm -rf ./okexchain-patches
fi
git reset --soft $long_commit_id
copy_command="COPY . ./exchain"
make_command="RUN cd exchain && make $network WITH_ROCKSDB=true LINK_STATICALLY=true"
if [ "$type" = "explorer" ]; then
copy_command="COPY . ./exchain
COPY go-ethereum ./go-ethereum"
make_command="RUN cd exchain && go mod tidy && make $network WITH_ROCKSDB=true LINK_STATICALLY=true"
fi
echo "FROM okexchain/build-env:$base_env as builder
WORKDIR \$GOPATH/src/github.com/okx
ENV GO111MODULE=on GOPROXY=direct
$copy_command
$make_command
FROM okexchain/build-env:$base_env
COPY --from=builder \$GOPATH/bin/exchaind \$GOPATH/bin/exchaind
COPY --from=builder \$GOPATH/bin/exchaincli \$GOPATH/bin/exchaincli
RUN apk add --no-cache axel
ENTRYPOINT [\"/bin/bash\", \"-c\"]
CMD [\"exchaind start\"]
EXPOSE 26656 26657 26659 26660 6060" > Dockerfile
echo "生成的Dockerfile内容如下:"
cat Dockerfile
- name: Get current date
id: date
run: echo "DATE=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
- name: Get commit hash
id: commit
run: echo "HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Generate image tag
id: tag
run: |
BRANCH_TAG=$(echo "${{ github.event.inputs.branch || github.event.inputs.tag }}" | sed 's/\//_/g')
IMAGE_TAG="${BRANCH_TAG}_${DATE}_${HASH}"
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and Push Docker image
run: |
docker build -t "okexchain/${{ github.event.inputs.network }}-${{ github.event.inputs.type }}:${{ env.IMAGE_TAG }}" .
docker push "okexchain/${{ github.event.inputs.network }}-${{ github.event.inputs.type }}:${{ env.IMAGE_TAG }}"