-
Notifications
You must be signed in to change notification settings - Fork 2
53 lines (41 loc) · 2.28 KB
/
docker-publish-branch.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
name: Docker
on:
push:
branches-ignore:
- main
env:
IMAGE_NAME: universe-2020-demo
jobs:
push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Log into registry
run: echo "${{ secrets.DEMO_GITHUB_TOKEN }}" | docker login ghcr.io -u dfassbender --password-stdin
- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=${GITHUB_SHA::7}
LABEL=$(echo ${{github.event.ref}} | sed 's/refs\/heads\///g' | tr '[:upper:]' '[:lower:]' | awk -F "-" '{print $1 "-" $2 "-" $3}')
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
echo LABEL=$LABEL
docker tag $IMAGE_NAME $IMAGE_ID:$LABEL-$VERSION
docker push $IMAGE_ID:$LABEL-$VERSION
- name: Create deployment
run: |
# create a deployment associated with the created docker-image
SHORT_SHA=${GITHUB_SHA::7}
LABEL=$(echo ${{github.event.ref}} | sed 's/refs\/heads\///g' | tr '[:upper:]' '[:lower:]' | awk -F "-" '{print $1 "-" $2 "-" $3}')
PAYLOAD="{\"ref\":\"$SHORT_SHA\",\"environment\":\"$LABEL.test\",\"label\":\"$LABEL\",\"project\":\"${{ env.project }}\",\"description\":\"Deploy commit $SHORT_SHA\",\"auto_merge\":false,\"required_contexts\":[]}"
echo $(echo $PAYLOAD)
DEPLOYMENT_ID=$(curl -s -X POST -d "$PAYLOAD" -H 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -H "Accept:application/vnd.github.ant-man-preview+json" https://api.github.com/repos/spring-media/github-demo/deployments | jq '.id')
# set state of the deployment to "queued"
DEPLOYMENT_PAYLOAD="{\"environment\": \"$LABEL.test\",\"state\": \"queued\",\"description\": \"Deployment created\"}"
echo $(echo $DEPLOYMENT_PAYLOAD)
curl -s -X POST -d "$DEPLOYMENT_PAYLOAD" -H 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -H "Accept:application/vnd.github.flash-preview+json" https://api.github.com/repos/spring-media/github-demo/deployments/"$DEPLOYMENT_ID"/statuses