-
Notifications
You must be signed in to change notification settings - Fork 1
/
Taskfile.dist.yml
181 lines (150 loc) · 5.99 KB
/
Taskfile.dist.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
version: "3"
tasks:
# --------------------------------
# LOCAL DEVELOPMENT
# --------------------------------
templ:
cmds:
- templ generate
local-dataservice-temp-fix:
cmds:
- task: prepare-fake-gcs-volume
- defer: docker stop fake-gcs-server && docker rm fake-gcs-server
- docker run -d --name fake-gcs-server -p 4443:4443 -v ${PWD}/local_data:/storage fsouza/fake-gcs-server -scheme http -data /storage
- RUN_TEST=true RUN_LOCAL=true go run cmd/dataservice/main.go
local-dataservice:
cmds:
- task: prepare-fake-gcs-volume
- defer: docker network rm itchgrep-network
- docker network create itchgrep-network
- defer: docker stop fake-gcs-server && docker rm fake-gcs-server
- docker run -d --name fake-gcs-server --network itchgrep-network -p 4443:4443 -v ${PWD}/local_data:/storage fsouza/fake-gcs-server -scheme http -data /storage
- docker build . -t itchgrep-dataservice -f "Dockerfile.dataservice"
- defer: docker stop itchgrep-dataservice && docker rm itchgrep-dataservice
- docker run --name itchgrep-dataservice --network itchgrep-network -p 8080:8080 -e RUN_LOCAL=true itchgrep-dataservice
local-webserver:
cmds:
- task: prepare-fake-gcs-volume
- defer: docker network rm itchgrep-network
- docker network create itchgrep-network
- defer: docker stop fake-gcs-server && docker rm fake-gcs-server
- docker run -d --name fake-gcs-server --network itchgrep-network -p 4443:4443 -v ${PWD}/local_data:/storage fsouza/fake-gcs-server -scheme http -data /storage
- docker build . -t itchgrep-webserver -f "Dockerfile.webserver"
- defer: docker stop itchgrep-webserver && docker rm itchgrep-webserver
- docker run --name itchgrep-webserver --network itchgrep-network -p 8080:8080 -e PAGE_SIZE=36 -e RUN_LOCAL=true itchgrep-webserver
# --------------------------------
# DEPLOYMENT
# --------------------------------
gcloud-setup:
cmds:
- gcloud auth login
- gcloud config set project "{{.PROJECT_ID}}"
- gcloud auth configure-docker
vars:
PROJECT_ID: itchgrep
deploy-all:
cmds:
- task: deploy-webserver
- task: deploy-dataservice
deploy-webserver:
cmds:
- docker build -f Dockerfile.webserver -t "gcr.io/{{.PROJECT_ID}}/webserver" .
- docker push "gcr.io/{{.PROJECT_ID}}/webserver"
- gcloud run deploy webserver
--image "gcr.io/{{.PROJECT_ID}}/webserver"
--platform managed
--allow-unauthenticated
--region "{{.REGION}}"
vars:
PROJECT_ID: itchgrep
REGION: europe-west1
deploy-dataservice:
cmds:
- docker build -f Dockerfile.dataservice -t "gcr.io/{{.PROJECT_ID}}/dataservice" .
- docker push "gcr.io/{{.PROJECT_ID}}/dataservice"
- gcloud run deploy dataservice
--image "gcr.io/{{.PROJECT_ID}}/dataservice"
--platform managed
--no-allow-unauthenticated
--region "{{.REGION}}"
--no-cpu-throttling
--memory 1500Mi
vars:
PROJECT_ID: itchgrep
REGION: europe-west1
create-dataservice-scheduler-job:
cmds:
- echo "Using $SERVICE_ACCOUNT_EMAIL"
- echo "Using $DATASERVICE_URL"
- gcloud scheduler jobs create http dataservice-job
--schedule="0 0 * * *"
--http-method=GET
--uri="$DATASERVICE_URL/trigger-fetch"
--oidc-service-account-email="$SERVICE_ACCOUNT_EMAIL"
--oidc-token-audience="$DATASERVICE_URL"
--location="{{.LOCATION}}"
preconditions:
# SERVICE_ACCOUNT_EMAIL and DATASERVICE_URL must be specified via
# env vars. don't include them here for security purposes.
- test -n "$SERVICE_ACCOUNT_EMAIL"
- test -n "$DATASERVICE_URL"
vars:
# paris is not supported for cloud scheduler
LOCATION: europe-west1
# --------------------------------
# TESTING
# --------------------------------
test:
cmds:
- task: test-storage
test-storage:
silent: false
env:
RUN_TEST: true
RUN_LOCAL: true
cmds:
- echo "Testing Storage Package"
- task: prepare-temp-fake-gcs-volume
- defer: { task: clean-temp-fake-gcs-volume }
- defer: { task: clean-fake-gcs-server }
- cmd: docker run -d --name fake-gcs-server -p 4443:4443 -v ${PWD}/.tmp_local_data:/data fsouza/fake-gcs-server -scheme http -data /data -backend memory > /dev/null
silent: true
- go test -v internal/storage/*.go
# --------------------------------
# INTERNAL TASKS, NOT FOR RUNNING
# --------------------------------
clean-fake-gcs-server:
internal: true
silent: true
cmds:
- docker stop fake-gcs-server > /dev/null && docker rm fake-gcs-server > /dev/null
prepare-fake-gcs-volume:
internal: true
silent: true
cmds:
- mkdir -p "$(pwd)/local_data/itchgrep-data/"
# we have to do the if check because the fake gcs container chowns the
# files to root (does not appear to reacht to --user flag)
- if [ ! -f "$(pwd)/local_data/itchgrep-data/.COME_ON_DOCKER" ];
then touch "$(pwd)/local_data/itchgrep-data/.COME_ON_DOCKER";
fi
# the `touch` is required because otherwise the directory won't be
# created in the container, causing interaction with the bucket to 404
prepare-temp-fake-gcs-volume:
internal: true
silent: true
cmds:
- rm -rf "$(pwd)/.tmp_local_data/"
- mkdir -p "$(pwd)/.tmp_local_data/itchgrep-data/"
# we have to do the if check because the fake gcs container chowns the
# files to root (does not appear to reacht to --user flag)
- if [ ! -f "$(pwd)/.tmp_local_data/.COME_ON_DOCKER" ];
then touch "$(pwd)/.tmp_local_data/.COME_ON_DOCKER";
fi
# the `touch` is required because otherwise the directory won't be
# created in the container, causing interaction with the bucket to 404
clean-temp-fake-gcs-volume:
internal: true
silent: true
cmds:
- rm -rf "$(pwd)/.tmp_local_data/"