Skip to content

Commit 9cc6b64

Browse files
🚀 Deploy: add deploy config files and github action, closes #56 (#67)
Deploy using https://fly.io and hopefully staying in the free tier. Contact @camerondurham for accessing dashboards and logs. Verify with: ```bash curl --request POST \ --url http://runner.fly.dev:10100/api/v1/run \ --header 'Content-Type: application/json' \ --data '{ "source": "print('\''what is up my dudes'\'')", "language":"python3" }' ```
1 parent 0307c12 commit 9cc6b64

File tree

15 files changed

+68
-35
lines changed

15 files changed

+68
-35
lines changed

.devcontainer/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ RUN apt-get update -y \
77
&& go install github.com/spf13/cobra/[email protected] \
88
&& go install github.com/golang/mock/[email protected]
99

10-
EXPOSE 8080
10+
EXPOSE 10100
1111
ENTRYPOINT ["/bin/bash"]

.devcontainer/devcontainer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
"eamodio.gitlens"
88
],
99
"forwardPorts": [
10-
8080
10+
10100
1111
]
1212
}

.github/workflows/flyctl-deploy.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Fly Deploy
2+
on:
3+
push:
4+
branches:
5+
- main
6+
env:
7+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
8+
jobs:
9+
deploy:
10+
name: Deploy app
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: superfly/flyctl-actions/setup-flyctl@master
15+
- run: flyctl deploy --remote-only --dockerfile docker/server-debian/Dockerfile

Makefile

+3-14
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@ all:
1616
@echo ""
1717
@echo " run-api: run the API server"
1818
@echo ""
19-
@echo " run-api-bg: run the API server in the background"
20-
@echo ""
2119
@echo " run-mock: run the mock API server"
2220
@echo ""
23-
@echo " run-mock-bg: run the mock API server in the background"
24-
@echo ""
2521
@echo " kill-api: kill the API server"
2622
@echo ""
2723
@echo " test: run all unit tests in the repo"
@@ -40,20 +36,16 @@ all:
4036
@echo ""
4137
@echo " dkr-server: build and run server using Docker"
4238
@echo ""
43-
@echo " dkr-dev: build and run runtime processor using Docker"
44-
@echo ""
4539
@echo " dkr-stop-mock: stop and remove mock container"
4640
@echo ""
4741
@echo " dkr-stop-server: stop and remove server container"
4842
@echo ""
49-
@echo " dkr-stop-dev: stop and remove dev container"
50-
@echo ""
5143

5244
dkr-build-mock:
5345
docker build -t ${MOCK_SERVER_NAME}:${VERSION} -f docker/mock-server/Dockerfile .
5446

5547
dkr-mock: dkr-build-mock
56-
docker run -d -p 8080:8080 --name ${MOCK_SERVER_NAME} ${MOCK_SERVER_NAME}:${VERSION}
48+
docker run -d -p 10100:10100 --name ${MOCK_SERVER_NAME} ${MOCK_SERVER_NAME}:${VERSION}
5749

5850
# retire this command since we will likely stick with debian server
5951
dkr-build-alpine:
@@ -66,10 +58,7 @@ dkr-build-dev:
6658
docker build -t ${DEV_NAME}:${VERSION} -f .devcontainer/Dockerfile .
6759

6860
dkr-server: dkr-build-server
69-
docker run -d -p 8080:8080 -e DEBUG=1 --name ${SERVER_NAME} ${SERVER_NAME}:${VERSION}
70-
71-
dkr-dev: dkr-build-dev
72-
docker run -it -p 8080:8080 --rm -v ${PWD}:/runner --name ${DEV_NAME} ${DEV_NAME}:${VERSION}
61+
docker run -d -p 10100:10100 -e DEBUG=1 --name ${SERVER_NAME} ${SERVER_NAME}:${VERSION}
7362

7463
dkr-stop-mock:
7564
docker stop ${MOCK_SERVER_NAME}
@@ -125,4 +114,4 @@ install-hooks:
125114
cp ./hack/hooks/* .git/hooks/
126115
@echo "done"
127116

128-
.PHONY: build lint test
117+
.PHONY: build lint test

cli/runner/client/client.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
// TODO: fill in this client package as needed and create, use Client as needed in CLI commands
1616

1717
const (
18-
DEFAULT_URL = "http://localhost:8080"
18+
DEFAULT_URL = "http://localhost:10100"
1919
LANG_ENDPOINT = "/api/v1/languages"
2020
RUN_ENDPOINT = "/api/v1/run"
2121
)
@@ -62,19 +62,22 @@ func (c *Client) Run(r *api.RunRequest) (*api.RunResponse, error) {
6262
// TODO: implement/refactor
6363
source := r.Source
6464

65-
body := strings.NewReader(source)
65+
reqBody := api.RunRequest{
66+
Source: source,
67+
Lang: r.Lang,
68+
}
69+
70+
jsonBody, err := json.Marshal(reqBody)
71+
PanicCheck(err)
72+
73+
body := strings.NewReader(string(jsonBody))
74+
6675
req, err := http.NewRequest("POST", c.BaseUrl+RUN_ENDPOINT, body)
6776
if err != nil {
6877
return nil, err
6978
}
7079
req.Header.Add("Content-Type", "application/json")
7180

72-
cookie := http.Cookie{
73-
Name: "language",
74-
Value: string(r.Lang),
75-
}
76-
req.AddCookie(&cookie)
77-
7881
resp, err := c.HttpClient.Do(req)
7982
if err != nil {
8083
return nil, err

docker/mock-server/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ FROM golang:1.17.6-alpine3.15
88
# FROM scratch
99
WORKDIR /runner
1010
COPY --from=builder /runner/mock-server ./
11-
EXPOSE 8080
11+
EXPOSE 10100
1212
ENTRYPOINT ["/runner/mock-server"]

docker/server-alpine/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ COPY --from=builder /runner/process /usr/bin
1616
COPY --from=builder /runner/runner-server ./
1717
# TODO: do this in the server
1818
RUN groupadd -g 1234 runner1 && useradd -u 1234 -g runner1 -d /tmp/runner1 runner1
19-
EXPOSE 8080
19+
EXPOSE 10100
2020
ENTRYPOINT ["/runner/runner-server"]

docker/server-debian/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ COPY --from=builder /runner/runner-server ./
1414
COPY docker/server-debian/entrypoint.sh /runner/entrypoint.sh
1515
RUN apt-get update \
1616
&& apt-get install -y python3
17-
EXPOSE 8080
17+
EXPOSE 10100
1818
ENTRYPOINT ["/runner/entrypoint.sh", "server"]
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
services:
2+
backend:
3+
build:
4+
dockerfile: docker/server-debian/Dockerfile
5+
context: ../../
6+
ports:
7+
- 10100:10100
8+
deploy:
9+
mode: replicated
10+
replicas: 1
11+
endpoint_mode: dnsrr

fly.toml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# fly.toml file generated for runner on 2022-04-09T18:03:25-07:00
2+
3+
app = "runner"
4+
5+
6+
[env]
7+
PORT = "10100"
8+
9+
[[services]]
10+
internal_port = 10100
11+
protocol = "tcp"
12+
13+
[[services.ports]]
14+
handlers = ["http"]
15+
port = "10100"

hack/kill_server.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ kports() {
55
if [[ "$#" != "0" ]]; then
66
ports="$1"
77
else
8-
ports="8080"
8+
ports="10100"
99
fi
1010

1111
processes=$(lsof -i:"${ports}")

readme.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ make run-mock
162162
# run the mock API server in the background (you'll have to use `make kill-api` to shut down)
163163
make run-mock-bg
164164

165-
# kill the server (mock or not) if it's running (this works by killing the process using port 8080, the API port)
165+
# kill the server (mock or not) if it's running (this works by killing the process using port 10100, the API port)
166166
make kill-api
167167

168168
# run all tests in the repository
@@ -231,21 +231,21 @@ go run api/main.go
231231
```
232232

233233
Usually you'll want to run the server in the background to you can do other
234-
things with your terminal. However, you'd need to kill the process running on port `8080`
234+
things with your terminal. However, you'd need to kill the process running on port `10100`
235235
once you're done. You can use the `api/kill_server.sh` script for this.
236236

237237
```bash
238238
# 1. run the API in the background
239239
go run api/main.go &
240240

241-
# 2. once you are done, use the script to shut down processes on port 8080
241+
# 2. once you are done, use the script to shut down processes on port 10100
242242
./api/kill_server.sh
243243

244244
```
245245

246246
You can also use the `api/kill_server.sh` script if you see this error:
247247

248-
> error starting server: listen tcp :8080: bind: address already in use
248+
> error starting server: listen tcp :10100: bind: address already in use
249249
250250
### Go Tips
251251

server/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
const (
21-
API_PORT = ":8080"
21+
API_PORT = ":10100"
2222
SERVER_REQUEST_TIMEOUT = 10
2323
)
2424

server/mock-server/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
const (
19-
API_PORT = ":8080"
19+
API_PORT = ":10100"
2020
SERVER_REQUEST_TIMEOUT = 10
2121
)
2222

server/test_server_startup.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sleep 5
1212
# child process process id
1313
server_pid=$!
1414

15-
response=$(curl -X GET localhost:8080/api/v1/languages)
15+
response=$(curl -X GET localhost:10100/api/v1/languages)
1616
if [ -z "$response" ]; then
1717
echo "no response from languages endpoint"
1818
kill -9 $server_pid

0 commit comments

Comments
 (0)