@@ -0,0 +1,80 @@
1+name: Build Docker Image
2+on:
3+ push:
4+ branches:
5+ - master
6+
7+jobs:
8+ build:
9+ name: build-docker
10+ runs-on: ubuntu-latest
11+ steps:
12+ - name: Configure git credentials
13+ run: |
14+ git config --global credential.helper '!f() { echo "username=${{ secrets.GH_USERNAME }}"; echo "password=${{ secrets.GH_ACCESS_TOKEN }}"; }; f'
15+
16+ - uses: actions/checkout@v2
17+ with:
18+ repo: Aviora/dm
19+ fetch-depth: 0 # fetch all history
20+
21+ - name: Checkout submodules
22+ shell: bash
23+ run: |
24+ git submodule sync --recursive
25+ git submodule update --init --force --recursive --depth=1
26+
27+ - name: Configure AWS Credentials
28+ uses: aws-actions/configure-aws-credentials@v1
29+ with:
30+ aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
31+ aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
32+ aws-region: us-east-1
33+
34+ - name: Login to Amazon ECR
35+ id: login-ecr
36+ uses: aws-actions/amazon-ecr-login@v1
37+
38+ - name: Set up remote builds
39+ id: remote
40+ run: |
41+ tempdir=/tmp/dm_$(date +%Y%m%d%H%M%S)
42+
43+ # set up ssh keys
44+ mkdir -p ~/.ssh
45+ echo "${{ secrets.builder_ssh_key }}" > $HOME/.ssh/builder
46+ echo -e "\nHost builder\n\tHostName ${{ secrets.builder_addr }}\n\tServerAliveInterval 30\n\tServerAliveCountMax 5\n\tUser nix\n\tStrictHostKeyChecking no\n\tIdentityFile $HOME/.ssh/builder" | sudo tee /etc/ssh/ssh_config
47+ echo -e "echo ${{ secrets.builder_addr }}\tbuilder" | sudo tee /etc/hosts
48+ chmod 0500 $HOME/.ssh/builder
49+ ssh builder uname
50+ rsync --exclude '.git' -lr ./ builder:$tempdir
51+ echo "##[set-output name=tempdir;]$tempdir"
52+
53+ - name: Build and push image to Amazon ECR
54+ env:
55+ tempdir: ${{ steps.remote.outputs.tempdir }}
56+ ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
57+ ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPOSITORY }}
58+ IMAGE_TAG: ${{ github.sha }}
59+ run: |
60+ # build docker images
61+ ssh builder "cd $tempdir; mkdir tmp; ./release.sh ci tmp"
62+
63+ # push docker images to ECR
64+ for app in dmc dms; do
65+ image_name=`ssh builder "cat $tempdir/$app-docker" | docker load | awk '{print $3}'`
66+ docker tag $image_name $ECR_REGISTRY/$app:$IMAGE_TAG
67+ docker tag $image_name $ECR_REGISTRY/$app:latest
68+ docker push $ECR_REGISTRY/$app:$IMAGE_TAG
69+ done
70+ for app in dmc dms; do
71+ docker push $ECR_REGISTRY/$app:latest
72+ done
73+
74+ - name: Clean up
75+ if: always()
76+ env:
77+ tempdir: ${{ steps.remote.outputs.tempdir }}
78+ run: |
79+ docker logout ${{ steps.login-ecr.outputs.registry }}
80+ ssh builder "rm -rf $tempdir"