forked from saleor/saleor
-
Notifications
You must be signed in to change notification settings - Fork 0
148 lines (127 loc) · 4.86 KB
/
publish-containers.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: Publish
on:
push:
tags:
# Matches stable and pre-releases
- "[0-9]+.[0-9]+.[0-9]+*"
branches:
- main
- ci/**
jobs:
docker:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
# Outputs the name of the repository (owner/repo)
- name: Build Image Name
id: image
run: |
# The name of the owner and of the repository: owner/repository
IMAGE_NAME=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
echo ::set-output name=image_name::${IMAGE_NAME}
# Outputs container tags for tagged pushes starting by 'v'
# Pushes only to GitHub Container Repository (ghcr.io)
#
# Tags stable versions as :latest
# Pre-releases, alphas, etc. as :snapshot
- name: Prepare Image Tags from Git Tag
id: tagged
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
set -x
# Remove everything else than the tagged version
VERSION=${GITHUB_REF#refs/tags/}
# Tag as stable (:latest) if there is no letters in the version
# Otherwise, tag as preview (:snapshot)
if [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
# Matches 1.0.0, 1.0.1, etc.
NAMED_VERSION="latest"
else
# Matches 1.0.0a1, 1.0.0rc1, etc.
NAMED_VERSION="snapshot"
fi
TAGS=$"\
ghcr.io/${{ steps.image.outputs.image_name }}:${NAMED_VERSION},\
ghcr.io/${{ steps.image.outputs.image_name }}:${VERSION}\
"
# Output the target tags
echo "
CONTAINER_TAGS=${TAGS}
NAMED_VERSION=${NAMED_VERSION}
VERSION=${VERSION}
" >> "${GITHUB_ENV}"
# Outputs the containers tags for staging branches
# Only publishes them onto Docker Hub
- name: Prepare Tags for Staging
id: staging
if: ${{ startsWith(github.ref, 'refs/heads/') }}
run: |
set -x
# Version name is the branch name
# Slashes are substitued by dashes
CLEAN_BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)
# Target GHCR with the branch name as the tag, e.g. unstable-main
TAGS=$"\
ghcr.io/${{ steps.image.outputs.image_name }}:unstable-${CLEAN_BRANCH_NAME}
"
# Set version name for open-containers version label as:
# <branch>-<drift>-g<6-digit-hash>
NAMED_VERSION=$(git describe --all --long | tr -d $'\n')
# Output the target tags
echo "
CONTAINER_TAGS=${TAGS}
NAMED_VERSION=${NAMED_VERSION}
" >> "${GITHUB_ENV}"
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.CR_USERNAME }}
password: ${{ secrets.CR_PAT }}
- name: Build and Push
id: docker_build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
context: ./
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.CONTAINER_TAGS }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
build-args: |
PROJECT_VERSION=${{ env.NAMED_VERSION }}
COMMIT_ID=${{ github.sha }}
- name: Image digest
run: |
echo $"\
Digest: ${{ steps.docker_build.outputs.digest }}
Tags: ${{ env.CONTAINER_TAGS }}"
- name: Trigger staging deployments for tagged release
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
curl -f -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${{ secrets.SALEOR_RELEASE_TOKEN }}" \
https://api.github.com/repos/saleor/saleor-multitenant/dispatches \
-d "{\"event_type\":\"deploy-staging\",\"client_payload\":{\"version\":\"$VERSION\"}}"
curl -f -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${{ secrets.SALEOR_RELEASE_TOKEN }}" \
https://api.github.com/repos/saleor/saleor-cloud-deployments/dispatches \
-d "{\"event_type\":\"deploy-demo-staging\",\"client_payload\":{\"version\":\"$VERSION\"}}"