Skip to content

Commit

Permalink
Update to Apodini 0.3.0 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
PSchmiedmayer authored Jul 17, 2021
1 parent 9909026 commit f3ff5fb
Show file tree
Hide file tree
Showing 19 changed files with 406 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"--security-opt", "seccomp=unconfined"
],
"appPort": [
8080
80
],
"extensions": [
"pvasek.sourcekit-lsp--dev-unofficial",
Expand Down
25 changes: 25 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# *Name of the PR*

## :recycle: Current situation
*Describe the current situation (if possible with and exemplary (or real) code snippet and/or where this is used)*

## :bulb: Proposed solution
*Describe the solution (if possible with and exemplary (or real) code snippet)*

### Problem that is solved
*Provide a description and link issues that are solved*

### Implications
*Describe the implications, e.g. refactoring*

## :heavy_plus_sign: Additional Information
*Provide some additional information if possible*

### Related PRs
*Reference the related PRs*

### Testing
*Are there tests included? If yes, which situations are tested and which corner cases are missing?*

### Reviewer Nudging
*Where should the reviewer start, where is a good entry point?*
20 changes: 20 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
branches: [release]
name-template: '$NEXT_PATCH_VERSION'
tag-template: '$NEXT_PATCH_VERSION'
categories:
- title: '🚀 Features'
labels:
- 'feature'
- 'enhancement'
- title: '🐛 Bug Fixes'
labels:
- 'fix'
- 'bugfix'
- 'bug'
- title: '🧰 Maintenance'
label: 'chore'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
template: |
## Changes
$CHANGES
52 changes: 25 additions & 27 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,45 @@ on:
push:
branches:
- develop
- release
pull_request:
branches:
- develop
- release

jobs:
linux:
name: Linux ${{ matrix.linux }} ${{ matrix.configuration }}
container:
image: swift:5.3-${{ matrix.linux }}
macoswebservices:
name: macOS
runs-on: macos-11
steps:
- uses: actions/checkout@v2
- uses: maxim-lobanov/[email protected]
with:
xcode-version: latest
- name: Check Xcode version
run: xcodebuild -version
- name: Check Swift version
run: swift --version
- name: Build and test
run: swift test
linuxwebservices:
name: Linux ${{ matrix.linux }}
runs-on: ubuntu-latest
container:
image: swift:${{ matrix.linux }}
strategy:
fail-fast: false
matrix:
linux: [bionic, xenial, focal, amazonlinux2, centos8]
configuration: [debug, release, release_testing]
linux: [focal, bionic, amazonlinux2, centos8]
steps:
- uses: actions/checkout@v2
- name: Install libsqlite3, lsof and zsh
- name: Install libsqlite3
if: ${{ !(startsWith( matrix.linux, 'centos' ) || startsWith( matrix.linux, 'amazonlinux' )) }}
run: apt-get update && apt-get install -y --no-install-recommends libsqlite3-dev lsof zsh
run: apt-get update && apt-get install -y --no-install-recommends libsqlite3-dev
- name: Install libsqlite3
if: startsWith( matrix.linux, 'amazonlinux' )
run: yum update -y && yum install -y sqlite-devel lsof zsh
run: yum update -y && yum install -y sqlite-devel
- name: Install libsqlite3
if: startsWith( matrix.linux, 'centos' )
run: yum update -y --nobest && yum install -y sqlite-devel lsof zsh
- uses: actions/cache@v2
with:
path: .build
key: ${{ runner.os }}-${{matrix.linux}}-spm-${{ hashFiles('Package.resolved') }}
run: yum update -y --nobest && yum install -y sqlite-devel
- name: Check Swift version
run: swift --version

- name: Release Build # Ensuring release build runs successfully without -enable-testing flag
if: matrix.configuration == 'release'
run: swift build -c release
- name: Release Build & Test
if: matrix.configuration == 'release_testing'
run: swift test -c release --enable-test-discovery -Xswiftc -enable-testing -Xswiftc -DRELEASE_TESTING
- name: Debug Build & Test
if: matrix.configuration == 'debug'
run: swift test -c debug --enable-test-discovery
- name: Build and test
run: swift test -Xswiftc -Xfrontend -Xswiftc -sil-verify-none
26 changes: 26 additions & 0 deletions .github/workflows/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build Docker Compose

on:
push:
branches:
- develop
pull_request:
branches:
- develop

jobs:
dockercompose:
name: Docker Compose Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Start containers
run: docker-compose -f docker-compose-development.yml up -d --build
- name: Test web service
run: |
sleep 3
curl --fail http://localhost/v1/
- name: Stop containers
if: always()
run: docker-compose down
41 changes: 41 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build Docker Image

on:
push:
tags:
- '*.*.*'

jobs:
docker:
name: Docker Build and Push Image
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Get latest tag
id: latesttag
uses: WyriHaximus/github-action-get-previous-tag@v1
with:
fallback: latest
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up docker buildx
uses: docker/setup-buildx-action@v1
with:
install: true
- name: Log in to the container registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push docker image
id: buildandpush
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: ghcr.io/apodini/template:latest,ghcr.io/apodini/template:${{ steps.latesttag.outputs.tag }}
- name: Image digest
run: echo ${{ steps.buildandpush.outputs.digest }}
14 changes: 14 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Release Drafter

on:
push:
branches:
- release

jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15 changes: 15 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Create Release

on:
push:
tags:
- '*.*.*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: GH Release
uses: softprops/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
9 changes: 8 additions & 1 deletion .github/workflows/swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: SwiftLint

on: pull_request
on:
pull_request:
paths:
- '.github/workflows/swiftlint.yml'
- '.swiftlint.yml'
- '**/*.swift'

jobs:
swiftlint:
Expand All @@ -11,3 +16,5 @@ jobs:
uses: norio-nomura/[email protected]
with:
args: --strict
env:
DIFF_BASE: ${{ github.base_ref }}
6 changes: 3 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"label": "build",
"type": "shell",
"command": "swift build",
"command": "swift build -Xswiftc -Xfrontend -Xswiftc -sil-verify-none",
"group": {
"kind": "build",
"isDefault": true
Expand All @@ -16,7 +16,7 @@
{
"label": "buildtests",
"type": "shell",
"command": "swift build --build-tests --enable-test-discovery"
"command": "swift build -Xswiftc -Xfrontend -Xswiftc -sil-verify-none --build-tests"
}
]
}
}
64 changes: 64 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# ================================
# Build image
# ================================
FROM swift:5.4-focal 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 \
&& apt-get install -y libsqlite3-dev \
&& rm -rf /var/lib/apt/lists/*

# Set up a build area
WORKDIR /build

# Copy all source files
COPY . .

# Build everything, with optimizations
RUN swift build -Xswiftc -Xfrontend -Xswiftc -sil-verify-none -c release

# 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)/WebService" ./

# Copy resources from the resources directory if the directories exist
# Ensure that by default, neither the directory nor any of its contents are writable.
RUN [ -d "$(swift build --package-path /build -c release --show-bin-path)/Apodini_ApodiniOpenAPI.resources" ] \
&& mv "$(swift build --package-path /build -c release --show-bin-path)/Apodini_ApodiniOpenAPI.resources" ./ \
&& chmod -R a-w ./Apodini_ApodiniOpenAPI.resources \
|| echo No resources to copy
RUN [ -d "$(swift build --package-path /build -c release --show-bin-path)/WebService_ApodiniTemplate.resources" ] \
&& mv "$(swift build --package-path /build -c release --show-bin-path)/WebService_ApodiniTemplate.resources" ./ \
&& chmod -R a-w ./WebService_ApodiniTemplate.resources \
|| echo No resources to copy

# ================================
# Run image
# ================================
FROM swift:5.4-focal-slim

# Make sure all system packages are up to date.
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
&& apt-get -q update \
&& apt-get -q dist-upgrade -y \
&& rm -r /var/lib/apt/lists/*

# Create a apodini user and group with /app as its home directory
RUN useradd --user-group --create-home --system --skel /dev/null --home-dir /app apodini

# Switch to the new home directory
WORKDIR /app

# Copy built executable and any staged resources from builder
COPY --from=build --chown=apodini:apodini /staging /app

# Ensure all further commands run as the apodini user
USER apodini:apodini

# Start the Apodini service when the image is run.
# The default port is 80. Can be adapted using the `--port` argument
ENTRYPOINT ["./WebService"]
Loading

0 comments on commit f3ff5fb

Please sign in to comment.