forked from kcp-dev/kcp
-
Notifications
You must be signed in to change notification settings - Fork 0
65 lines (56 loc) · 2.55 KB
/
kcp-image.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
name: Build and Publish KCP Image
permissions:
packages: write
on:
push:
branches:
- main
- 'release-*'
jobs:
kcp-image:
if: github.repository_owner == 'kcp-dev'
name: Build and Publish KCP Image
environment: unstable
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: v1.17
- name: Get the short sha
id: vars
run: echo "::set-output name=sha_short::$(echo ${{ github.sha }} | cut -b -7)"
# Build and push a KCP image, tagged with latest and the commit SHA.
- name: Build KCP Image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: kcp
tags: latest ${{ steps.vars.outputs.sha_short }}
containerfiles: |
./Dockerfile
- name: Push to ghcr.io
id: push-to-ghcr
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ghcr.io/${{ github.repository_owner }}
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Set up kubectl and kustomize
run: |-
curl -sL "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv4.5.2/kustomize_v4.5.2_linux_amd64.tar.gz" | tar xzf -
curl -sLO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod u+x ./kubectl
chmod u+x ./kustomize
- name: Get the external hostname
id: external_hostname
run: echo "::set-output name=external_hostname::$(./kubectl --server=https://${{ secrets.CICD_KUBE_HOST }} --token=${{ secrets.CICD_KUBE_TOKEN }} -n ${{ secrets.CICD_KUBE_NS }} get route kcp -o jsonpath='{.spec.host}')"
- name: Deploy new image to CI
id: deploy-to-ci
run: |-
cd manifest
../kustomize edit add patch --patch='[{"op": "replace", "path": "/spec/template/spec/containers/0/env", "value": [{"name": "EXTERNAL_HOSTNAME", "value": "${{ steps.external_hostname.outputs.external_hostname }}"}]}]' --group apps --kind Deployment --name kcp --version v1
../kustomize edit set image ghcr.io/kcp-dev/kcp=ghcr.io/${{ github.repository }}:${{ steps.vars.outputs.sha_short }}
../kustomize build . | ../kubectl --server=https://${{ secrets.CICD_KUBE_HOST }} --token=${{ secrets.CICD_KUBE_TOKEN }} -n ${{ secrets.CICD_KUBE_NS }} apply -f -