Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b7f9da7
Showing
4 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.swp | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM alpine | ||
WORKDIR /b | ||
RUN apk add --update gcc libc-dev | ||
ADD app.c ./ | ||
RUN gcc -O1 -static app.c | ||
|
||
FROM scratch | ||
COPY --from=0 /b/a.out /a | ||
CMD ["/a"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#define _POSIX_C_SOURCE 200112L | ||
|
||
#include <stdio.h> | ||
#include <netinet/in.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/socket.h> | ||
#include <sys/types.h> | ||
#include <unistd.h> | ||
|
||
int main() { | ||
|
||
const char *head = "HTTP/1.0 200\r\nContent-type: text/plain\r\n\r\n"; | ||
char buf[256] = {}; | ||
memcpy(buf, head, strlen(head)); | ||
if (0 != gethostname(buf + strlen(buf), sizeof(buf))) { | ||
return 4; | ||
} | ||
|
||
strcat(buf, "\n"); | ||
|
||
int sockfd = socket(AF_INET, SOCK_STREAM, 0); | ||
|
||
#ifdef REUSEADDR | ||
int enable = 1; | ||
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) { | ||
return 5; | ||
} | ||
#endif | ||
|
||
struct sockaddr_in servaddr = {}; | ||
servaddr.sin_family = AF_INET; | ||
servaddr.sin_addr.s_addr = htonl(INADDR_ANY); | ||
servaddr.sin_port = htons(1337); | ||
if (0 != bind(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr))) { | ||
return 1; | ||
} | ||
|
||
if (0 != listen(sockfd, 50)) { | ||
return 2; | ||
} | ||
|
||
for (;;) { | ||
int conn = accept(sockfd, NULL, NULL); | ||
if (conn < 0) { | ||
return 3; | ||
} | ||
|
||
// errors intentionally ignored | ||
write(conn, buf, strlen(buf)); | ||
|
||
// without shutdown, curl sometimes gets the close before the data | ||
shutdown(conn, SHUT_RDWR); | ||
close(conn); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
kind: Deployment | ||
apiVersion: apps/v1 | ||
metadata: | ||
name: hosty | ||
spec: | ||
strategy: | ||
rollingUpdate: | ||
maxSurge: 1 | ||
maxUnavailable: 1 | ||
type: RollingUpdate | ||
replicas: 3 | ||
selector: | ||
matchLabels: | ||
name: hosty | ||
template: | ||
metadata: | ||
labels: | ||
name: hosty | ||
spec: | ||
containers: | ||
- name: app | ||
image: faux/hostname-reply | ||
ports: | ||
- containerPort: 1337 | ||
readinessProbe: | ||
httpGet: | ||
path: / | ||
port: 1337 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: hosty | ||
spec: | ||
type: ClusterIP | ||
ports: | ||
- port: 80 | ||
targetPort: 1337 | ||
selector: | ||
name: hosty |