-
Notifications
You must be signed in to change notification settings - Fork 5
141 lines (117 loc) · 5 KB
/
sandbox.yaml
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
name: Sanbox image to build on push to sandbox/<sandbox identifier> branch
on:
push:
branches:
- sandbox/**
pull_request:
types:
- opened
permissions:
contents: write
id-token: write
pull-requests: write
issues: write
env:
ALPINE_IMAGE: alpine:3.18.3
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Docker Buildx
if: startsWith(github.ref, 'refs/heads/sandbox/')
id: buildx
uses: docker/setup-buildx-action@v3
- name: Set up QEMU
if: startsWith(github.ref, 'refs/heads/sandbox/')
uses: docker/setup-qemu-action@v3
- name: Set up Go
if: startsWith(github.ref, 'refs/heads/sandbox/')
uses: actions/setup-go@v4
- name: Login to DockerHub
if: startsWith(github.ref, 'refs/heads/sandbox/')
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set version
if: startsWith(github.ref, 'refs/heads/sandbox/')
run: |
#get short commit sha that triggered the flow
echo git_hash="$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_ENV
# Extract everything before the first slash
branch_identifier=$(echo "$GITHUB_REF_NAME" | cut -d'/' -f2-)
# Replace slashes with dashes using sed
echo branch_identifier=$(echo "$branch_identifier" | sed 's/\//-/g') >> $GITHUB_ENV
- name: Set image tag
if: startsWith(github.ref, 'refs/heads/sandbox/')
run: |
# set image tag that includes service name, sandbox identifier and commit sha
image_tag="${{ env.branch_identifier }}-${{ env.git_hash }}"
echo image_tag_sha=$image_tag >> $GITHUB_ENV
- name: Build images with GoReleaser
if: startsWith(github.ref, 'refs/heads/sandbox/')
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release -f goreleaser/.goreleaser-snapshot.yaml --snapshot
env:
GITHUB_TOKEN: ${{ secrets.CI_BOT_TOKEN }}
DOCKER_BUILDX_BUILDER: "${{ steps.buildx.outputs.name }}"
DOCKER_BUILDX_CACHE_FROM: "type=gha"
DOCKER_BUILDX_CACHE_TO: "type=gha,mode=max"
ALPINE_IMAGE: ${{ env.ALPINE_IMAGE }}
SANDBOX_IMAGE: true
- name: Push Docker images
if: startsWith(github.ref, 'refs/heads/sandbox/')
run: |
docker tag kubeshop/testkube-operator:${{ env.git_hash }} kubeshop/testkube-sandbox:operator-${{ env.image_tag_sha }}
docker push kubeshop/testkube-sandbox:operator-${{ env.image_tag_sha }}
- name: Repository dispatch
if: startsWith(github.ref, 'refs/heads/sandbox/')
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.CI_BOT_TOKEN }}
repository: kubeshop/testkube-deployment
event-type: sandbox_image_update
client-payload: '{"ref_name": "${{ github.ref_name }}", "sandbox_repo": "kubeshop/testkube-sandbox"}'
- name: Output summary
if: startsWith(github.ref, 'refs/heads/sandbox/')
run: |
echo -e "### Sandbox Environment" >> $GITHUB_STEP_SUMMARY
echo -e '```' >> $GITHUB_STEP_SUMMARY
echo -e "## URLs" >> $GITHUB_STEP_SUMMARY
echo "- Dashboard: https://dashboard.${{ github.ref_name }}.testkube.dev" >> $GITHUB_STEP_SUMMARY
echo "- API: https://api.${{ github.ref_name }}.testkube.dev" >> $GITHUB_STEP_SUMMARY
echo "- Agent: https://agent.${{ github.ref_name }}.testkube.dev" >> $GITHUB_STEP_SUMMARY
echo "- Storage: https://storage.${{ github.ref_name }}.testkube.dev" >> $GITHUB_STEP_SUMMARY
echo "- Websockets: https://websockets.${{ github.ref_name }}.testkube.dev" >> $GITHUB_STEP_SUMMARY
echo -e '```' >> $GITHUB_STEP_SUMMARY
- name: Get a branch name if PR is created
if: startsWith(github.event.pull_request.head.ref, 'sandbox/')
run: |
# get a branch name
branch_ref="${{ github.event.pull_request.head.ref }}"
#remove slash
branch_ref="${branch_ref#*/}"
#create env var
echo "branch_ref=$branch_ref" >> $GITHUB_ENV
- name: Render template
if: startsWith(github.event.pull_request.head.ref, 'sandbox/')
id: template
uses: chuhlomin/[email protected]
with:
template: .github/comment-template.md
vars: |
branch_ref: ${{ env.branch_ref }}
- name: Create comment on a PR with the endpoints
if: startsWith(github.event.pull_request.head.ref, 'sandbox/')
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.CI_BOT_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: ${{ steps.template.outputs.result }}