-
Notifications
You must be signed in to change notification settings - Fork 150
133 lines (107 loc) · 3.96 KB
/
infra-release.yml
File metadata and controls
133 lines (107 loc) · 3.96 KB
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
name: Deployment artifacts
on:
release:
types:
- published
# Run tests for any PRs.
pull_request:
env:
IMAGE_NAME: penn-chime
KUBE_CONFIG_DATA: ${{ secrets.kubeconfig_data_preprod }}
# For hub CLI tool
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run tests
run: |
if [ -f docker-compose.test.yml ]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
docker build . --file Dockerfile
fi
release-data:
runs-on: ubuntu-latest
if: github.event_name == 'release'
steps:
- uses: actions/checkout@v2
- name: Generate build metadata
run: |
IMAGE_PATH="docker.pkg.github.com/${GITHUB_REPOSITORY,,}/${IMAGE_NAME}"
# Tagged release
if [[ ${{ github.ref }} == refs/tags/* ]]; then
# Strip git ref prefix from version
TAGNAME=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
VERSION=$(echo $TAGNAME | sed -e 's/^v//')
else
VERSION=${{ github.sha }}
fi
IMAGE_ID=$IMAGE_PATH:$VERSION
echo "release/registry-path: $IMAGE_PATH"
echo "release/tag: $TAGNAME"
echo "release/version: $VERSION"
echo "release/registry-id: $IMAGE_ID"
mkdir release
printf '%s' "$IMAGE_PATH" > release/registry-path
printf '%s' "$TAGNAME" > release/tag
printf '%s' "$VERSION" > release/version
printf '%s' "$IMAGE_ID" > release/registry-id
- name: Expose release information
uses: actions/upload-artifact@v1
with:
name: release
path: release
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
publish-image:
# Ensure test job passes before pushing image.
needs:
- test
- release-data
runs-on: ubuntu-latest
if: github.event_name == 'release'
steps:
- uses: actions/checkout@v2
- name: Get release information
uses: actions/download-artifact@v1
with:
name: release
- name: Get deployment information
run: |
hub api /repos/${{ github.repository }}/deployments?ref=$(cat release/tag) -X GET | jq .[0] > /tmp/deployment.json
- name: Build image
run: docker build . --file Dockerfile --tag image
- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
- name: Push image
run: |
# Publish tag
image_id=$(cat release/registry-id)
docker tag image $image_id
docker push $image_id
# Only publish :latest tag for production releases
if ! ${{ github.event.release.prerelease }}; then
image_path=$(cat release/registry-path)
docker tag image $image_path:latest
docker push $image_path:latest
echo prod release published to :latest
fi
- name: Mark deployment as failed
if: failure()
run: |
hub api /repos/${{ github.repository }}/deployments/$(jq .id < /tmp/deployment.json)/statuses \
-X POST \
-H "Accept: application/json, application/vnd.github.flash-preview+json" \
--input <(cat <<EOF
{
"state": "failure",
"description": "Error in job publish-image",
"log_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
EOF)