-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (87 loc) · 3.35 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
on:
workflow_call:
inputs:
protocol_name:
required: true
type: string
build_only:
required: false
type: boolean
secrets:
SSH_KEY:
required: false
name: Build
jobs:
build:
runs-on: ubuntu-20.04
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Build
run: docker build -t ${{ inputs.protocol_name }} .
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag ${{ inputs.protocol_name }} $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
update-inventory:
if: ${{ inputs.build_only }} != 'true'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
needs: [ build ]
steps:
- name: Digest
id: digest
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
docker pull $IMAGE_ID:$VERSION
DIGEST=`docker inspect --format='{{index .RepoDigests 0}}' $IMAGE_ID:$VERSION | awk -F'@' '{print $2}'`
echo "name=$IMAGE_ID" >> $GITHUB_OUTPUT
echo "digest=$DIGEST" >> $GITHUB_OUTPUT
- name: Generate
run: |
wget https://raw.githubusercontent.com/CoLearn-Dev/colink-protocol-inventory-workflow-templates/main/inventory-template-docker.toml -O ${{ inputs.protocol_name }}.toml
sed -i 's#{{docker.image.name}}#${{ steps.digest.outputs.name }}#' ${{ inputs.protocol_name }}.toml
sed -i 's#{{docker.image.digest}}#${{ steps.digest.outputs.digest }}#' ${{ inputs.protocol_name }}.toml
- name: SSH Agent
run: |
eval `ssh-agent`
ssh-add - <<< "${{ secrets.SSH_KEY }}"
echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> $GITHUB_ENV
- name: Clone inventory repository
run: git clone git@github.com:CoLearn-Dev/colink-protocol-inventory.git
- name: Copy
run: cp ${{ inputs.protocol_name }}.toml colink-protocol-inventory/protocols/
- name: Set pusher
run: |
git config --global user.email "104302037+colearn-dev-bot@users.noreply.github.com"
git config --global user.name "colearn-dev-bot"
- name: Add
working-directory: ./colink-protocol-inventory
run: git add protocols/${{ inputs.protocol_name }}.toml
- name: Commit
working-directory: ./colink-protocol-inventory
run: git commit -m "Update ${{ inputs.protocol_name }}"
- name: Push
working-directory: ./colink-protocol-inventory
run: git push