small container
This commit is contained in:
6
.github/workflows/docker-build.yml
vendored
6
.github/workflows/docker-build.yml
vendored
@@ -18,6 +18,12 @@ jobs:
|
|||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: '1.23'
|
go-version: '1.23'
|
||||||
|
|
||||||
|
- name: Download dependencies
|
||||||
|
run: go mod download
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: go build -o server src/main.go
|
||||||
|
|
||||||
- name: Log in to GitHub Container Registry
|
- name: Log in to GitHub Container Registry
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v2
|
||||||
|
|||||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
.env
|
||||||
7
docker-compose.yml
Normal file
7
docker-compose.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
web:
|
||||||
|
image: ghcr.io/jurajkubrican/knet/go-web-server:latest
|
||||||
|
ports:
|
||||||
|
- 5000:5000/tcp
|
||||||
15
dockerfile
15
dockerfile
@@ -1,24 +1,15 @@
|
|||||||
# Step 1: Build the Go binary
|
# Step 1: Build the Go binary
|
||||||
FROM golang:bookworm AS build
|
FROM scratch
|
||||||
|
|
||||||
# Set the current working directory inside the container
|
# Set the current working directory inside the container
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy go.mod and go.sum files
|
# Copy go.mod and go.sum files
|
||||||
COPY go.mod go.sum ./
|
COPY server ./
|
||||||
|
|
||||||
# Download all Go dependencies
|
|
||||||
RUN go mod download
|
|
||||||
|
|
||||||
# Copy the rest of the application code
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# Build the Go application
|
|
||||||
RUN go build -o main src/main.go
|
|
||||||
|
|
||||||
# Command to run the executable
|
# Command to run the executable
|
||||||
RUN chmod a+x main
|
RUN chmod a+x main
|
||||||
CMD ["./main"]
|
CMD ["./server"]
|
||||||
|
|
||||||
# Expose the port on which the Go server will run
|
# Expose the port on which the Go server will run
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
2
env
Normal file
2
env
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
GHCR_USERNAME=JurajKubrican
|
||||||
|
GHCR_TOKEN=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
|
||||||
30
index.php
Normal file
30
index.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
// URL of the backend server
|
||||||
|
$backend_url = "http://localhost:5000" . $_SERVER['REQUEST_URI'];
|
||||||
|
|
||||||
|
// Initialize cURL
|
||||||
|
$ch = curl_init($backend_url);
|
||||||
|
|
||||||
|
// Forward the request method (GET, POST, etc.) and headers
|
||||||
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $_SERVER['REQUEST_METHOD']);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
|
||||||
|
// Forward headers
|
||||||
|
foreach (getallheaders() as $header => $value) {
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, ["$header: $value"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle POST data if it exists
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents('php://input'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute the request
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
|
||||||
|
// Forward the response back to the client
|
||||||
|
http_response_code(curl_getinfo($ch, CURLINFO_HTTP_CODE));
|
||||||
|
echo $response;
|
||||||
|
|
||||||
|
// Close cURL
|
||||||
|
curl_close($ch);
|
||||||
Reference in New Issue
Block a user