Skip to content

Commit a203ba4

Browse files
committed
Update token
Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent 68aaf14 commit a203ba4

File tree

5 files changed

+36
-13
lines changed

5 files changed

+36
-13
lines changed

main.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@ limitations under the License.
1717
package main
1818

1919
import (
20-
"os"
21-
2220
"github.com/appscodelabs/gh-ci-webhook/pkg/cmds"
2321
_ "github.com/appscodelabs/gh-ci-webhook/pkg/providers/registry"
2422

2523
"gomodules.xyz/logs"
2624
)
2725

2826
func main() {
27+
if err := realMain(); err != nil {
28+
panic(err)
29+
}
30+
}
31+
32+
func realMain() error {
2933
logs.InitLogs()
3034
defer logs.FlushLogs()
3135

32-
if err := cmds.NewRootCmd().Execute(); err != nil {
33-
os.Exit(1)
34-
}
35-
os.Exit(0)
36+
return cmds.NewRootCmd().Execute()
3637
}

pkg/backend/stream.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ func (mgr *Manager) onerun(subj string) error {
121121
if err != nil {
122122
return err
123123
}
124-
defer mgr.streamCompleted.DeleteConsumer(ctx, cons.CachedInfo().Name)
124+
defer func() {
125+
err = mgr.streamCompleted.DeleteConsumer(ctx, cons.CachedInfo().Name)
126+
if err != nil {
127+
klog.Errorln(err)
128+
}
129+
}()
125130

126131
// FetchNoWait will not wait for new messages if the whole batch is not available at the time of sending request.
127132
msgs, err := cons.FetchNoWait(mgr.numWorkers)
@@ -134,7 +139,10 @@ func (mgr *Manager) onerun(subj string) error {
134139
if err != nil {
135140
klog.Errorln(err)
136141
}
137-
msg.DoubleAck(context.TODO())
142+
err = msg.DoubleAck(context.TODO())
143+
if err != nil {
144+
klog.Errorln(err)
145+
}
138146

139147
if slot, found := mgr.Provider.Next(); found {
140148
err := mgr.Provider.StartRunner(slot) // Not 1-1 mapping for the VM shut down to restarted
@@ -188,7 +196,10 @@ func (mgr *Manager) ProcessCompletedJobs() error {
188196
if err != nil {
189197
klog.Errorln(err)
190198
}
191-
msg.DoubleAck(context.TODO())
199+
err = msg.DoubleAck(context.TODO())
200+
if err != nil {
201+
klog.Errorln(err)
202+
}
192203

193204
if slot, found := mgr.Provider.Next(); found {
194205
err := mgr.Provider.StartRunner(slot) // Not 1-1 mapping for the VM shut down to restarted

pkg/cmds/wait_for_job.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ func consumeMsg(ctx context.Context, streamQueued jetstream.Stream, subj string)
141141
if err != nil {
142142
return nil, err
143143
}
144-
defer streamQueued.DeleteConsumer(ctx, cons.CachedInfo().Name)
144+
defer func() {
145+
err = streamQueued.DeleteConsumer(ctx, cons.CachedInfo().Name)
146+
if err != nil {
147+
klog.Errorln(err)
148+
}
149+
}()
145150

146151
/*
147152
Double-acking is a mechanism used in JetStream to ensure exactly once semantics in message processing.

pkg/providers/firecracker/cloud_init.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ func BuildData(ghToken string, instanceID int, ghUsernames ...string) (*MMDSConf
178178
//echo "Created by bash shell script" >> /test-userscript/userscript.txt
179179
//`
180180

181+
encDockerHubToken := "ZGNrcl9wYXRfTGhOV3VDdTNYeml0cWd5bmxrSE9wM1VoQVRnCg=="
182+
dockerHubToken, err := base64.StdEncoding.DecodeString(encDockerHubToken)
183+
if err != nil {
184+
return nil, err
185+
}
186+
181187
script := fmt.Sprintf(`#! /bin/bash
182188
set -x
183189
@@ -218,7 +224,7 @@ echo 127.0.1.1 $HOSTNAME.localdomain ${RUNNER_NAME} >> /etc/hosts
218224
chmod a+w /usr/local/bin
219225
220226
# bypass docker hub rate limits
221-
docker login -u tigerworks -p dckr_pat_TQSHB3Z8CoNU8G4jtW7xXOxMefM
227+
docker login -u tigerworks -p %s
222228
223229
# Prepare GitHun Runner user
224230
export USER=runner
@@ -246,7 +252,7 @@ export RUNNER_NAME=%s
246252
# ephemeral runner: https://docs.github.com/en/actions/hosting-your-own-runners/autoscaling-with-self-hosted-runners#using-ephemeral-runners-for-autoscaling
247253
# https://github.blog/changelog/2021-09-20-github-actions-ephemeral-self-hosted-runners-new-webhooks-for-auto-scaling/
248254
curl -fsSL https://gist.githubusercontent.com/tamalsaha/af2f99c80f84410253bd1e532bdfabc7/raw/a3fa2a82ae14d406fd934b90f2be7dc2945607a8/start-runner.sh | bash -s -- -n ${RUNNER_NAME} -f
249-
`, DefaultOptions.NatsURL, DefaultOptions.NatsUsername, DefaultOptions.NatsPassword, ghToken, runnerName)
255+
`, string(dockerHubToken), DefaultOptions.NatsURL, DefaultOptions.NatsUsername, DefaultOptions.NatsPassword, ghToken, runnerName)
250256

251257
udBytes, err := PrepareCloudInitUserData(userData, script)
252258
if err != nil {

pkg/providers/linode/linode.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func createInstance(c *linodego.Client, machineName string) (int, error) {
165165
func waitForStatus(c *linodego.Client, id int, status linodego.InstanceStatus) error {
166166
attempt := 0
167167
klog.Infoln("waiting for instance status", "status", status)
168-
return wait.PollImmediate(RetryInterval, RetryTimeout, func() (bool, error) {
168+
return wait.PollUntilContextTimeout(context.TODO(), RetryInterval, RetryTimeout, true, func(ctx context.Context) (bool, error) {
169169
attempt++
170170

171171
instance, err := c.GetInstance(context.Background(), id)

0 commit comments

Comments
 (0)