-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshippable.yml
More file actions
110 lines (100 loc) · 4.06 KB
/
shippable.yml
File metadata and controls
110 lines (100 loc) · 4.06 KB
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
resources:
- name: factorio-repo
type: gitRepo
integration: "trriplejay github"
versionTemplate:
sourceName: SoftSrv/factorio
branch: master
- name: factorio-slack
type: notification
integration: factorio-slack
versionTemplate:
recipients:
- "#factorio"
- name: digitalocean-creds
type: integration
integration: digitalocean-creds
- name: factorio-do-keys
type: integration
integration: factorio-do-keys
- name: factorio-trigger
type: notification
integration: factorio-trigger
- name: factorio-hook
type: webhook
versionTemplate:
webhookKey: four-fluffy-feathers-on-a-fiffer-feffer-fef
jobs:
- name: factorio-controller
type: runSh
allowPublicAccess: true
steps:
- IN: digitalocean-creds
- IN: factorio-hook
- IN: factorio-do-keys
- IN: factorio-repo
switch: off
- IN: factorio-slack
- TASK:
name: cycle-do-box
runtime:
options:
env:
- fVersion: "0.16"
- snapshotName: "factorio-ss"
- snapshotId: ""
- dropletId: ""
- region: sfo2
- size: s-1vcpu-2gb
- skip: ""
script:
- pushd $(shipctl get_resource_state factorio-repo)
- source send_msg.sh
- echo "starting..."
- shipctl copy_file_from_prev_state state.env .
- if [ -f "state.env" ]; then source state.env; fi
- >
if [ "$JOB_TRIGGERED_BY_NAME" == "factorio-hook" ]; then
HOOK_META=$(shipctl get_resource_meta factorio-hook)
export message=$(shipctl get_json_value "$HOOK_META/version.json" "version.propertyBag.payload.text")
export slack_user=$(shipctl get_json_value "$HOOK_META/version.json" "version.propertyBag.payload.user_name")
if [ "$message" == "start" ] && [ -z $snapshotId ]; then
ls
send_msg "Skipping start. The server should already be running."
skip=true
elif [ "$message" == "stop" ] && [ -z $dropletId ]; then
send_msg "Skipping stop. The server is already stopped."
skip=true
elif [ "$message" != "stop" ] && [ "$message" != "start" ]; then
send_msg "Bad command '$message'. only 'start' or 'stop' are accepted"
skip=true
else
if [ -n $slack_user ]; then
send_msg "$message action initiated by $slack_user"
else
send_msg "$message action initiated by $JOB_TRIGGERED_BY_NAME"
fi
fi
elif [ "$FORCE_ACTION" == "rebuild" ]; then
send_msg "Rebuild has been forced."
echo "forcing rebuild from snapshotId $init_snapshotId"
export snapshotId="$init_snapshotId"
export dropletId=""
elif [ "$FORCE_ACTION" == "destroy" ]; then
send_msg "Destroy has been forced."
echo "forcing destruction of dropletId $init_dropletId"
export snapshotId=""
export dropletId="$init_dropletId"
elif [ "$FORCE_ACTION" == "reset" ]; then
send_msg "Forcing state reset. No action will be taken on the droplet."
echo "export snapshotId=\"$init_snapshotId\"" > state.env
echo "export dropletId=\"$init_dropletId\"" >> state.env
shipctl copy_file_to_state state.env
skip=true
fi
- if [ -z "$skip" ]; then ./cycle.sh; fi
- if [ -n "$skip" ]; then shipctl copy_file_from_prev_state state.env $JOB_STATE; fi
on_failure:
script:
- send_msg "An error occured. see <$BUILD_URL|here> for more details"
- shipctl copy_file_from_prev_state state.env $JOB_STATE