Code Monkey home page Code Monkey logo

swift-server's Introduction

Test Swift avec Docker

WIP

Swift to test with a Docker

Reproduce

Init with swift package init --type executable

Usage

  cd Sources
  swift run server

Build

Debug: swift build

Release: swift build -c release

Remove build artefact

swift package clean

Remove build directory

swift package reset

Build for Linux

podman run --rm \
  -v "$PWD:/workspace" \
  -w /workspace \
  <SWIFT_DOCKER_IMAGE>  \
  /bin/bash -cl ' \
     swift build && \
     rm -rf .build/install && mkdir -p .build/install && \
     cp -P .build/debug/NIOHTTP1Server .build/install/ && \
     cp -P /usr/lib/swift/linux/lib*so* .build/install/'
podman run --rm \
  -v "$PWD:/workspace" \
  -w /workspace \
  swift:5.10  \
  /bin/bash -cl ' \
     swift build && \
     rm -rf .build/install && mkdir -p .build/install && \
     cp -P .build/release/server .build/install/ && \
     cp -P /usr/lib/swift/linux/lib*so* .build/install/'

Deploy a Docker image

Dockerfile example:

# 1
## <OPTIONAL_ARCHITECTURE>/swift:<TAG_VERSION>
#FROM swift:5.10.0
FROM amd64/swift:5.10.0
WORKDIR /app
COPY . .

# 2
#RUN apt-get update && apt-get install libsqlite3-dev

# 3
RUN swift package clean
RUN swift build

# 4
RUN mkdir /app/bin
RUN mv `swift build --show-bin-path` /app/bin

# 5
EXPOSE 9080
#ENTRYPOINT ./bin/debug/Run serve --env local --hostname 0.0.0.0
ENTRYPOINT ./bin/debug/server

First build it: podman build . -tag <TAG>

Then save it: podman save -o <OUTPUT_FILE> localhost/<TAG>

Send to the server: scp <OUTPUT_FILE> <USERNAME>@<HOST>:~/

Add it to local podman instance: podman load -i <OUTPUT_FILE>

Finally run it: podman run -d --rmi -p 9080:9080 localhost/<TAG>

Remark: The is saved in the saved imaged, that's why we are using the same value from one machine to another

Remark: In the Dockerfile, the image used is base on amd64 architecture because the targer server.

Reference

Swift Programming Language Book

Swift on Server

(https://www.swift.org/documentation/server/guides/packaging.html)

(https://www.swift.org/documentation/server/guides/deploying/ubuntu.html)

(https://www.kodeco.com/26322368-developing-and-testing-server-side-swift-with-docker-and-vapor?page=2#toc-anchor-007)

Use of FoundationNetworking framework for Linux instead of Foundation: Some types and related have been split out of Foundation framework (only for Linux - MacOS still find those types in Foundation).

swift-server's People

Contributors

sprohaszka avatar sprohaszka-ledger avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.