33 push :
44 tags :
55 - v*
6+ branches :
7+ - master
8+
69jobs :
7- build :
10+ # Builds and pushes the Docker image to Docker Hub and ECR
11+ push-to-registries :
812 runs-on : ubuntu-latest
913 steps :
10- - name : Set output
11- id : vars
12- run : echo ::set-output name=tag::${GITHUB_REF#refs/*/}
14+ - name : Prepare tags
15+ id : tags
16+ shell : python
17+ run : |
18+ import datetime
19+
20+ timestamp = str(int(datetime.datetime.now().timestamp()))
21+ base_ecr_tag = '${{ secrets.AWS_ECR_URL }}:'
22+ base_dockerhub_tag = 'docker.io/hathornetwork/tx-mining-service:'
23+
24+ tags = set()
25+
26+ ref = '${{ github.ref }}'
27+ if ref.startswith('refs/tags/'):
28+ version = ref[10:].split('-', 1)[0]
29+
30+ tags.add(base_ecr_tag + version)
31+ tags.add(base_ecr_tag + 'latest')
32+
33+ tags.add(base_dockerhub_tag + version)
34+ tags.add(base_dockerhub_tag + 'latest')
35+ elif ref == 'refs/heads/master':
36+ tags.add(base_ecr_tag + 'staging-${{ github.sha }}-' + timestamp)
37+ else:
38+ tags.add(base_ecr_tag + 'dev-${{ github.sha }}-' + timestamp)
39+
40+ print("::set-output name=tags::" + ",".join(tags))
1341 - name : Set up QEMU
1442 uses : docker/setup-qemu-action@27d0a4f181a40b142cce983c5393082c365d1480
1543 - name : Set up Docker Buildx
@@ -19,11 +47,17 @@ jobs:
1947 with :
2048 username : ${{ secrets.DOCKERHUB_USERNAME }}
2149 password : ${{ secrets.DOCKERHUB_TOKEN }}
50+ - name : Login to AWS ECR
51+ uses : docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
52+ with :
53+ registry : ${{ secrets.AWS_ECR_URL}}
54+ username : ${{ secrets.AWS_ACCESS_KEY_ID }}
55+ password : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
2256 - name : Build and push
2357 uses : docker/build-push-action@a66e35b9cbcf4ad0ea91ffcaf7bbad63ad9e0229
2458 with :
2559 push : true
26- tags : hathornetwork/tx-mining-service:latest,hathornetwork/tx-mining-service: ${{ steps.vars .outputs.tag }}
60+ tags : ${{ steps.tags .outputs.tags }}
2761 platforms : linux/amd64,linux/arm64
2862 cache-from : type=gha
2963 cache-to : type=gha,mode=max
0 commit comments