-
Notifications
You must be signed in to change notification settings - Fork 2
159 lines (142 loc) · 6.19 KB
/
build_images.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
149
150
151
152
153
154
155
156
name: Build Marketplace Images (AWS/DigitalOcean)
on:
workflow_call:
inputs:
tag:
required: true
type: string
source:
required: false
type: string
default: amazon-ebs.aws-ami,digitalocean.do-marketplace
secrets:
github-token:
required: true
digitalocean-token:
required: true
aws-secret-key:
required: true
aws-key-id:
required: true
env:
PACKER_REPO: RocketChat/rocketchat-packer
TESTS_REPO: debdutdeb/rocket.chat.tests
jobs:
build-aws:
runs-on: ubuntu-latest
if: ${{ contains(inputs.source, 'amazon-ebs.aws-ami') }}
steps:
- name: Build AWS image
uses: RocketChat/packer-configs@main
with:
aws-key-id: ${{ secrets.aws-key-id }}
aws-secret-key: ${{ secrets.aws-secret-key }}
tag: ${{ inputs.tag }}
source: amazon-ebs.aws-ami
is-aws-working:
runs-on: ubuntu-latest
needs:
- build-aws
steps:
- name: Clone test repository
uses: actions/checkout@v3
with:
repository: ${{ env.TESTS_REPO }}
submodules: true
path: tests
- name: Verify aws ami
shell: bash
env:
AWS_DEFAULT_REGION: us-east-1
AWS_SECRET_ACCESS_KEY: ${{ secrets.aws-secret-key }}
AWS_ACCESS_KEY_ID: ${{ secrets.aws-key-id }}
ROCKETCHAT_MAX_ATTEMPTS: "250"
run: |
sudo apt install jq jo -y
ami_id=$(aws ec2 describe-images --region us-east-1 --filters "Name=creation-date,Values="$(date '+%Y-%m-%d')"*" --filters ${{ format('Name=name,Values=rocket-chat-{0}*', inputs.tag) }} --output text --query 'Images[0].ImageId')
group_id=$(aws ec2 create-security-group --description "rocket.chat ${{ inputs.tag }}" --group-name bats-${{ inputs.tag }} --query GroupId --output text)
aws ec2 authorize-security-group-ingress --group-id $group_id --protocol tcp --port '0-65535' --cidr '0.0.0.0/0'
instance_id=$(aws ec2 run-instances --count 1 --image-id $ami_id --instance-type t2.medium --security-group-ids $group_id --query 'Instances[0].InstanceId' --output text)
aws ec2 wait instance-running --instance-id $instance_id
rocketchat_host_public_ip=$(aws ec2 describe-instances --instance-id $instance_id --query "Reservations[0].Instances[0].PublicIpAddress" --output text)
[[ -n "$rocketchat_host_public_ip" ]]
export ROCKETCHAT_TAG="${{ inputs.tag }}"
export ROCKETCHAT_URL="http://${rocketchat_host_public_ip}:3000"
cd tests && . _.bash && bats api_basic/ || status=$?
aws ec2 terminate-instances --instance-ids "$instance_id"
aws ec2 wait instance-terminated --instance-id $instance_id
aws ec2 delete-security-group --group-id $group_id
exit $status
build-digitalocean:
runs-on: ubuntu-latest
if: ${{ contains(inputs.source, 'digitalocean.do-marketplace') }}
steps:
- name: Build DigitalOcean image
uses: RocketChat/packer-configs@main
with:
digitalocean-token: ${{ secrets.digitalocean-token }}
tag: ${{ inputs.tag }}
source: digitalocean.do-marketplace
is-digitalocean-working:
needs:
- build-digitalocean
runs-on: ubuntu-latest
steps:
- name: Clone test repository
uses: actions/checkout@v3
with:
repository: ${{ env.TESTS_REPO }}
submodules: true
path: tests
- name: Verify digitalocean image
shell: bash
env:
ROCKETCHAT_MAX_ATTEMPTS: "250"
DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.digitalocean-token }}
run: |
wget https://github.com/digitalocean/doctl/releases/download/v1.84.0/doctl-1.84.0-linux-amd64.tar.gz &&
tar xf doctl-1.84.0-linux-amd64.tar.gz &&
sudo mv doctl /usr/local/bin
sudo apt-get install --no-install-recommends jq jo -y
image_id=$(doctl compute snapshot ls --format ID --no-header "rocket-chat-${{ inputs.tag }}-*" | tail -1)
rocketchat_host_public_ip=$(doctl compute droplet create --image "$image_id" --size s-2vcpu-4gb --region blr1 --format PublicIPv4 --no-header --wait bats-${{ inputs.tag }})
[[ -n "$rocketchat_host_public_ip" ]]
export ROCKETCHAT_URL="http://${rocketchat_host_public_ip}:3000"
export ROCKETCHAT_TAG=${{ inputs.tag }}
cd tests && . _.bash && bats api_basic/ || status=$?
doctl compute droplet delete bats-${{ inputs.tag }} --force
exit $status
create-github-release:
needs:
- is-digitalocean-working
- is-aws-working
runs-on: ubuntu-latest
steps:
- name: Create release
uses: softprops/action-gh-release@v1
with:
repository: ${{ env.PACKER_REPO }}
token: ${{ secrets.github-token }}
name: ${{ inputs.tag }}
tag_name: ${{ inputs.tag }}
body: ${{ format('https://github.com/RocketChat/Rocket.Chat/releases/{0}', inputs.tag) }}
draft: false
update-digitalocean-marketplace-listing:
needs:
- is-digitalocean-working
runs-on: ubuntu-latest
steps:
- name: Update marketplace listing
shell: bash
env:
DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.digitalocean-token }}
run: |
wget https://github.com/digitalocean/doctl/releases/download/v1.84.0/doctl-1.84.0-linux-amd64.tar.gz &&
tar xf doctl-1.84.0-linux-amd64.tar.gz &&
sudo mv doctl /usr/local/bin
sudo apt-get install jo --no-install-recommends -y
image_id="$(doctl compute snapshot list --format ID 'rocket-chat-${{ inputs.tag }}-*' --no-header | tail -1)" # TODO: get it out of packer
# TODO: add software versions array
payload="$(jo reasonForUpdate='new release' imageId=$image_id version=${{ inputs.tag }} releaseNotes='https://github.com/RocketChat/packer-configs/releases/${{ inputs.tag }}')"
echo "payload: $payload"
curl -XPATCH https://api.digitalocean.com/api/v1/vendor-portal/apps/5cbf905da6e1a17be804b006/versions/${{ inputs.tag }} -d "$payload" -H "Authorization: Bearer $DIGITALOCEAN_ACCESS_TOKEN"