vapor again

This commit is contained in:
2023-09-11 21:08:38 -07:00
parent 96073ed048
commit 7f3586cd36
23 changed files with 424 additions and 39 deletions

77
Dockerfile Normal file
View File

@@ -0,0 +1,77 @@
# ================================
# Build image
# ================================
FROM swift:5.7-jammy as build
# Install OS updates and, if needed, sqlite3
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
&& apt-get -q update \
&& apt-get -q dist-upgrade -y\
&& rm -rf /var/lib/apt/lists/*
# Set up a build area
WORKDIR /build
# First just resolve dependencies.
# This creates a cached layer that can be reused
# as long as your Package.swift/Package.resolved
# files do not change.
COPY ./Package.* ./
RUN swift package resolve
# Copy entire repo into container
COPY . .
# Build everything, with optimizations
RUN swift build -c release --static-swift-stdlib
# Switch to the staging area
WORKDIR /staging
# Copy main executable to staging area
RUN cp "$(swift build --package-path /build -c release --show-bin-path)/Run" ./
# Copy resources bundled by SPM to staging area
RUN find -L "$(swift build --package-path /build -c release --show-bin-path)/" -regex '.*\.resources$' -exec cp -Ra {} ./ \;
# Copy any resources from the public directory and views directory if the directories exist
# Ensure that by default, neither the directory nor any of its contents are writable.
RUN [ -d /build/Public ] && { mv /build/Public ./Public && chmod -R a-w ./Public; } || true
RUN [ -d /build/Resources ] && { mv /build/Resources ./Resources && chmod -R a-w ./Resources; } || true
# ================================
# Run image
# ================================
FROM ubuntu:jammy
# Make sure all system packages are up to date, and install only essential packages.
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
&& apt-get -q update \
&& apt-get -q dist-upgrade -y \
&& apt-get -q install -y \
ca-certificates \
tzdata \
# If your app or its dependencies import FoundationNetworking, also install `libcurl4`.
# libcurl4 \
# If your app or its dependencies import FoundationXML, also install `libxml2`.
# libxml2 \
&& rm -r /var/lib/apt/lists/*
# Create a vapor user and group with /app as its home directory
RUN useradd --user-group --create-home --system --skel /dev/null --home-dir /app vapor
# Switch to the new home directory
WORKDIR /app
# Copy built executable and any staged resources from builder
COPY --from=build --chown=vapor:vapor /staging /app
# Ensure all further commands run as the vapor user
USER vapor:vapor
# Let Docker bind to port 8080
EXPOSE 8080
# Start the Vapor service when the image is run, default to listening on 8080 in production environment
ENTRYPOINT ["./Run"]
CMD ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]

203
Package.resolved Normal file
View File

@@ -0,0 +1,203 @@
{
"pins" : [
{
"identity" : "async-http-client",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swift-server/async-http-client.git",
"state" : {
"revision" : "864c8d9e0ead5de7ba70b61c8982f89126710863",
"version" : "1.15.0"
}
},
{
"identity" : "async-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/async-kit.git",
"state" : {
"revision" : "9acea4c92f51a5885c149904f0d11db4712dda80",
"version" : "1.16.0"
}
},
{
"identity" : "console-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/console-kit.git",
"state" : {
"revision" : "447f1046fb4e9df40973fe426ecb24a6f0e8d3b4",
"version" : "4.6.0"
}
},
{
"identity" : "leaf",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/leaf.git",
"state" : {
"revision" : "6fe0e843c6599f5189e45c7b08739ebc5c410c3b",
"version" : "4.2.4"
}
},
{
"identity" : "leaf-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/leaf-kit.git",
"state" : {
"revision" : "62169b44cc79734e11bf44b8d7154865dee5936b",
"version" : "1.10.1"
}
},
{
"identity" : "multipart-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/multipart-kit.git",
"state" : {
"revision" : "0d55c35e788451ee27222783c7d363cb88092fab",
"version" : "4.5.2"
}
},
{
"identity" : "routing-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/routing-kit.git",
"state" : {
"revision" : "ffac7b3a127ce1e85fb232f1a6271164628809ad",
"version" : "4.6.0"
}
},
{
"identity" : "swift-algorithms",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-algorithms.git",
"state" : {
"revision" : "b14b7f4c528c942f121c8b860b9410b2bf57825e",
"version" : "1.0.0"
}
},
{
"identity" : "swift-atomics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-atomics.git",
"state" : {
"revision" : "ff3d2212b6b093db7f177d0855adbc4ef9c5f036",
"version" : "1.0.3"
}
},
{
"identity" : "swift-backtrace",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swift-server/swift-backtrace.git",
"state" : {
"revision" : "f25620d5d05e2f1ba27154b40cafea2b67566956",
"version" : "1.3.3"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2",
"version" : "1.0.4"
}
},
{
"identity" : "swift-crypto",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto.git",
"state" : {
"revision" : "da0fe44138ab86e380f40a2acbd8a611b07d3f64",
"version" : "2.4.0"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "32e8d724467f8fe623624570367e3d50c5638e46",
"version" : "1.5.2"
}
},
{
"identity" : "swift-metrics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-metrics.git",
"state" : {
"revision" : "e8bced74bc6d747745935e469f45d03f048d6cbd",
"version" : "2.3.4"
}
},
{
"identity" : "swift-nio",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "45167b8006448c79dda4b7bd604e07a034c15c49",
"version" : "2.48.0"
}
},
{
"identity" : "swift-nio-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-extras.git",
"state" : {
"revision" : "d75ed708d00353acf173ca23018b6bd46f949464",
"version" : "1.17.0"
}
},
{
"identity" : "swift-nio-http2",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-http2.git",
"state" : {
"revision" : "38feec96bcd929028939107684073554bf01abeb",
"version" : "1.25.2"
}
},
{
"identity" : "swift-nio-ssl",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-ssl.git",
"state" : {
"revision" : "4fb7ead803e38949eb1d6fabb849206a72c580f3",
"version" : "2.23.0"
}
},
{
"identity" : "swift-nio-transport-services",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-transport-services.git",
"state" : {
"revision" : "c0d9a144cfaec8d3d596aadde3039286a266c15c",
"version" : "1.15.0"
}
},
{
"identity" : "swift-numerics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-numerics",
"state" : {
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
"version" : "1.0.2"
}
},
{
"identity" : "vapor",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/vapor.git",
"state" : {
"revision" : "bac0fe31e3b186537eb750d44fae048681e2b773",
"version" : "4.74.0"
}
},
{
"identity" : "websocket-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/websocket-kit.git",
"state" : {
"revision" : "2b8885974e8d9f522e787805000553f4f7cce8a0",
"version" : "2.7.0"
}
}
],
"version" : 2
}

39
Package.swift Normal file
View File

@@ -0,0 +1,39 @@
// swift-tools-version:5.7
import PackageDescription
let package = Package(
name: "smparkin",
platforms: [
.macOS(.v12)
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
.package(url: "https://github.com/vapor/leaf.git", from: "4.0.0"),
],
targets: [
.target(
name: "App",
dependencies: [
.product(name: "Vapor", package: "vapor"),
.product(name: "Leaf", package: "leaf")
],
swiftSettings: [
.unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
]
),
.executableTarget(
name: "Run",
dependencies: [
.target(name: "App")
]
),
.testTarget(
name: "AppTests",
dependencies: [
.target(name: "App"),
.product(name: "XCTVapor", package: "vapor")
]
)
]
)

View File

Before

Width:  |  Height:  |  Size: 497 KiB

After

Width:  |  Height:  |  Size: 497 KiB

View File

Before

Width:  |  Height:  |  Size: 544 KiB

After

Width:  |  Height:  |  Size: 544 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 MiB

After

Width:  |  Height:  |  Size: 1.0 MiB

View File

Before

Width:  |  Height:  |  Size: 1.0 MiB

After

Width:  |  Height:  |  Size: 1.0 MiB

View File

Before

Width:  |  Height:  |  Size: 466 KiB

After

Width:  |  Height:  |  Size: 466 KiB

1
README.md Normal file
View File

@@ -0,0 +1 @@
smpark.in

View File

@@ -13,7 +13,7 @@
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,700,900" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Montserrat:400,700,900" rel="stylesheet">
<!-- Custom stlylesheet --> <!-- Custom stlylesheet -->
<link type="text/css" rel="stylesheet" href="/static/css/404style.css" /> <link type="text/css" rel="stylesheet" href="/css/404style.css" />
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->

View File

@@ -19,7 +19,7 @@ body,h1,h2,h3,h4,h5,h6 {font-family: "Raleway", sans-serif}
<a href="#" onclick="w3_close()" class="w3-hide-large w3-right w3-jumbo w3-padding w3-hover-grey" title="close menu"> <a href="#" onclick="w3_close()" class="w3-hide-large w3-right w3-jumbo w3-padding w3-hover-grey" title="close menu">
<i class="fa fa-remove"></i> <i class="fa fa-remove"></i>
</a> </a>
<img src="/static/images/me.jpg" style="width:45%;" class="w3-round"><br><br> <img src="/images/me.jpg" style="width:45%;" class="w3-round"><br><br>
<h4><b>Stephen Parkinson</b></h4> <h4><b>Stephen Parkinson</b></h4>
<p class="w3-text-grey">Software Engineer</p> <p class="w3-text-grey">Software Engineer</p>
</div> </div>
@@ -41,7 +41,7 @@ body,h1,h2,h3,h4,h5,h6 {font-family: "Raleway", sans-serif}
<!-- Header --> <!-- Header -->
<header id="portfolio"> <header id="portfolio">
<a href="#"><img src="/static/images/me.jpg" style="width:65px;" class="w3-circle w3-right w3-margin w3-hide-large w3-hover-opacity"></a> <a href="#"><img src="/images/me.jpg" style="width:65px;" class="w3-circle w3-right w3-margin w3-hide-large w3-hover-opacity"></a>
<span class="w3-button w3-hide-large w3-xxlarge w3-hover-text-grey" onclick="w3_open()"><i class="fa fa-bars"></i></span> <span class="w3-button w3-hide-large w3-xxlarge w3-hover-text-grey" onclick="w3_open()"><i class="fa fa-bars"></i></span>
<div class="w3-container"> <div class="w3-container">
<h1><b></b></h1> <h1><b></b></h1>
@@ -51,7 +51,7 @@ body,h1,h2,h3,h4,h5,h6 {font-family: "Raleway", sans-serif}
<!-- About --> <!-- About -->
<div class="w3-row-padding w3-padding-16" id="about"> <div class="w3-row-padding w3-padding-16" id="about">
<div class="w3-col m6"> <div class="w3-col m6">
<img src="/static/images/trees.jpg" alt="A picture I took" style="width:100%"> <img src="/images/trees.jpg" alt="A picture I took" style="width:100%">
</div> </div>
</div> </div>

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,15 @@
import Leaf
import Vapor
// Called before your application initializes.
public func configure(_ app: Application) throws {
//leaf
app.views.use(.leaf)
//Register middleware
app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
app.middleware.use(ErrorMiddleware.default(environment: app.environment))
//routes
try routes(app)
}

20
Sources/App/routes.swift Normal file
View File

@@ -0,0 +1,20 @@
import Vapor
// Register your application's routes here.
public func routes(_ app: Application) throws {
app.get("") { req async throws -> View in
return try await req.view.render("home")
}
app.get("index.html") { req async throws -> View in
return try await req.view.render("home")
}
app.get("privacy") { req async throws -> View in
return try await req.view.render("privacy")
}
app.get("welcome") { req async throws -> View in
return try await req.view.render("welcome")
}
app.get("**") { req async throws -> View in
return try await req.view.render("404")
}
}

9
Sources/Run/main.swift Normal file
View File

@@ -0,0 +1,9 @@
import App
import Vapor
var env = try Environment.detect()
try LoggingSystem.bootstrap(from: &env)
let app = Application(env)
defer { app.shutdown() }
try configure(app)
try app.run()

View File

@@ -0,0 +1,12 @@
import XCTest
@testable import App
class AppTests: XCTestCase {
func testStub() throws {
XCTAssert(true)
}
static let allTests = [
("testStub", testStub),
]
}

11
Tests/LinuxMain.swift Normal file
View File

@@ -0,0 +1,11 @@
#if os(Linux)
import XCTest
@testable import AppTests
XCTMain([
// AppTests
testCase(AppTests.allTests),
])
#endif

30
app.py
View File

@@ -1,30 +0,0 @@
from flask import Flask, render_template, request, Response
from flask_api import status
import sys
app = Flask(__name__)
# main smpark.in stuff
@app.route('/', methods=["GET"])
def home():
return render_template('home.html')
@app.route('/welcome', methods=["GET"])
def welcome():
return render_template('welcome.html')
@app.route('/privacy', methods=["GET"])
def privacy():
return render_template('privacy.html')
@app.errorhandler(404)
def fourohfour():
return render_template('404.html')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)

30
docker-compose.yml Normal file
View File

@@ -0,0 +1,30 @@
# Docker Compose file for Vapor
#
# Install Docker on your system to run and test
# your Vapor app in a production-like environment.
#
# Note: This file is intended for testing and does not
# implement best practices for a production deployment.
#
# Learn more: https://docs.docker.com/compose/reference/
#
# Build images: docker-compose build
# Start app: docker-compose up app
# Stop all: docker-compose down
#
version: '3.7'
x-shared_environment: &shared_environment
LOG_LEVEL: ${LOG_LEVEL:-debug}
services:
app:
image: smparkin:latest
build:
context: .
environment:
<<: *shared_environment
ports:
- '8888:8888'
# user: '0' # uncomment to run as root for testing purposes even though Dockerfile defines 'vapor' user.
command: ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8888"]

View File

@@ -1,2 +0,0 @@
flask
flask_api