-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (110 loc) · 4.29 KB
/
build.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
name: Update gh docker image and triggers
on:
# Triggers the workflow on releases
push:
branches:
- main
tags:
- '*'
pull_request:
# Allow to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
build-image:
name: Build docker image
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Login to Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get the image id
id: get_image_id
run: |
IMAGE_ID=$(echo ghcr.io/${{ github.repository }} | tr '[A-Z]' '[a-z]')
echo ::set-output name=IMAGE_ID::$IMAGE_ID
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Get the version
id: get_version
run: |
VERSION="${{ steps.extract_branch.outputs.branch }}"
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "main" ] && VERSION=latest
echo ::set-output name=VERSION::$VERSION
- name: Build and push container image
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ steps.get_image_id.outputs.IMAGE_ID }}:${{ steps.get_version.outputs.VERSION }}
platforms: linux/amd64,linux/arm64
- name: Deploy to rancher # io-comune-test
if: github.ref == 'main'
uses: redturtle/[email protected]
with:
host: ${{ secrets.RANCHER_HOST }} # organization
api-username: ${{ secrets.RANCHER_API_USERNAME }} # organization
api-password: ${{ secrets.RANCHER_API_PASSWORD }} # organization
cluster-id: ${{ secrets.RANCHER_CLUSTER_ID }} # organization
project-id: ${{ secrets.RANCHER_PROJECT_ID }} # organization
namespace: ${{ secrets.RANCHER_NAMESPACE }}
workload: ${{ secrets.RANCHER_WORKLOAD }}
image: ${{ steps.get_image_id.outputs.IMAGE_ID }}:${{ steps.get_version.outputs.VERSION }}
slack-hook-url: ${{ secrets.RANCHER_SLACK_HOOK_URL }}
- name: Trigger job
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
run: |
curl --fail --request POST \
--form token=${{ secrets.TOKEN }} \
--form ref=main \
--form "variables[GITHUB_TAG]=${{ steps.get_version.outputs.VERSION }}" \
"https://gitlab.com/api/v4/projects/${{ secrets.PROJECT_ID }}/trigger/pipeline"
build-acceptance-image:
name: Build docker image for acceptance tests
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Login to Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get the image id
id: get_image_id
run: |
IMAGE_ID=$(echo ghcr.io/${{ github.repository }}-acceptance | tr '[A-Z]' '[a-z]')
echo ::set-output name=IMAGE_ID::$IMAGE_ID
- name: Get the version
id: get_version
run: |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "main" ] && VERSION=latest
echo ::set-output name=VERSION::$VERSION
- name: Build and push container image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile.acceptance
push: true
tags: ${{ steps.get_image_id.outputs.IMAGE_ID }}:${{ steps.get_version.outputs.VERSION }}
platforms: linux/amd64,linux/arm64