Skip to content

Commit

Permalink
🚧 Make tests for Linux
Browse files Browse the repository at this point in the history
πŸ› οΈ Improve docker scripts
☘ Fix recover job
☘ Fix Environment tests
  • Loading branch information
edmw committed Mar 8, 2020
1 parent b3e77f5 commit 47f197a
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 149 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
build/
.build/
.build_*

*.pbxuser
!default.pbxuser
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
- 🎁 Add functionality to move items between wishlists
- πŸ› οΈ Change handling of .env files: already existing env values will have precedence
- πŸ› οΈ Add automatic generation of LinuxMain.swift
- πŸ› οΈ Improve docker scripts
- ☘ Fix references on fluent models (again)
- ☘ Fix recover job
- ☘ Fix Environment tests

## [1.4.3]
- πŸ› οΈ Improve docker scripts
Expand Down
17 changes: 6 additions & 11 deletions Docker/build
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@
project=Wishlist
version=$1
label=$(echo "$project" | tr "[:upper:]" "[:lower:]")

echo
source "./Docker/functions"
check_version

if [[ ! -d "./$project.xcodeproj" ]] ; then
echo "πŸ€” Script must be run in project directory ..."; exit 1
fi
if [[ ! $version =~ ^[0-9]+(\.[0-9]+){2,2}(\-RC[0-9]+){0,1}$ ]];
then
echo "πŸ€” Script must be run with version number as argument ..."; exit 1
fi
docker_build_swift

echo "🐳 BUILDING Docker image for project $project with version $version"
echo "🐳 BUILDING IMAGE: Project $project with version $version"

out=$(docker build -f Docker/docker -t "$label:$version" . 2>&1)
[ $? -ne 0 ] \
&& echo "$out" \
&& echo "β›” Docker build command failed!" \
&& exit 1

image=$(docker image ls | grep " $version " | tr -s ' ' | cut -d' ' -f 1,2,3)
echo "😎 BUILD $image"
image=$(docker image ls | grep -E "^$label\s+$version " | tr -s ' ' | cut -d' ' -f 1,2,3)
echo "😎 BUILD IMAGE: $image"
10 changes: 1 addition & 9 deletions Docker/docker
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
FROM swift:5.1.4 AS builder
RUN apt-get -qq update \
&& apt-get -q -y install \
libssl-dev \
openssl \
tzdata \
zlib1g-dev \
&& rm -r /var/lib/apt/lists/*
FROM wishlist:swift AS builder
WORKDIR /app
COPY . .
RUN mkdir -p /build/lib && cp -R /usr/lib/swift/linux/lib* /build/lib
RUN swift build --configuration release --product "Wishlist" -Xswiftc "-suppress-warnings" -Xswiftc "-g" && mv `swift build --configuration release --show-bin-path` /build/bin

FROM ubuntu:18.04
Expand Down
50 changes: 0 additions & 50 deletions Docker/docker-compose.test

This file was deleted.

11 changes: 0 additions & 11 deletions Docker/docker.test

This file was deleted.

64 changes: 64 additions & 0 deletions Docker/functions
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
check_version() {
if [[ ! -d "./$project.xcodeproj" ]] ; then
echo "πŸ€” Script must be run in project directory ..."; exit 1
fi
if [[ ! $version =~ ^[0-9]+(\.[0-9]+){2,2}(\-RC[0-9]+){0,1}$ ]];
then
echo "πŸ€” Script must be run with version number as argument ..."; exit 1
fi
}

check_version_and_mode() {
if [[ ! -d "./$project.xcodeproj" ]] ; then
echo "πŸ€” Script must be run in project directory ..."; exit 1
fi
if [[ ! $version =~ ^[0-9]+(\.[0-9]+){2,2}(\-RC[0-9]+){0,1}$ ]];
then
echo "πŸ€” Script must be run with version number as first argument ..."; exit 1
fi
if [[ ! $mode =~ ^prod|dev$ ]] ; then
echo "πŸ€” Script must be run with mode (prod, dev) as second argument ..."; exit 1
fi
}

docker_build_swift () {
echo "🐳 BUILDING IMAGE: Swift for $project"

docker_in="$(cat <<-EOF
FROM swift:5.1.4
RUN apt-get -qq update \
&& apt-get -q -y install \
libssl-dev \
openssl \
tzdata \
zlib1g-dev \
&& rm -r /var/lib/apt/lists/*
RUN mkdir -p /build/lib && cp -R /usr/lib/swift/linux/lib* /build/lib
EOF
)"
out=$(echo "$docker_in" | docker build - -t "$label:swift" 2>&1)
[ $? -ne 0 ] \
&& echo "$out" \
&& echo "β›” Docker build command failed!" \
&& exit 1

image=$(docker image ls | grep -E "^$label\s+swift " | tr -s ' ' | cut -d' ' -f 1,2,3)
echo "😎 BUILD IMAGE: $image"
}

check_image() {
image=$(docker image ls | grep " $1 " | tr -s ' ' | cut -d' ' -f 3)
[ -z "$image" ] \
&& echo "β›” Image not found for version $1!" \
&& echo "πŸ’‘ Run build command first ..." \
&& exit 1
}

check_tagged_image() {
image=$(docker image ls | grep "$1\-$2 " | tr -s ' ' | cut -d' ' -f 1,2,3)
[ -z "$image" ] \
&& echo "β›” Image not found for label $1 and version $2!" \
&& echo "πŸ’‘ Run build command first ..." \
&& echo "πŸ’‘ Run tag command next ..." \
&& exit 1
}
23 changes: 6 additions & 17 deletions Docker/push
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,19 @@
project=Wishlist
version=$1
label=$(echo "$project" | tr "[:upper:]" "[:lower:]")

echo
source "./Docker/functions"
check_version

if [[ ! -d "./$project.xcodeproj" ]] ; then
echo "πŸ€” Script must be run in project directory ..."; exit 1
fi
if [[ ! $version =~ ^[0-9]+(\.[0-9]+){2,2}(\-RC[0-9]+){0,1}$ ]];
then
echo "πŸ€” Script must be run with version number as argument ..."; exit 1
fi
echo "🐳 PUSHING IMAGE: Project $project with version $version"

echo "🐳 PUSHING Docker image for project $project with version $version"

image=$(docker image ls | grep "$label\-$version " | tr -s ' ' | cut -d' ' -f 1,2,3)
[ -z "$image" ] \
&& echo "β›” Image not found for version $version!" \
&& echo "πŸ’‘ Run build command first ..." \
&& echo "πŸ’‘ Run tag command next ..." \
&& exit 1
check_tagged_image "$label" "$version"

out=$(docker push yamanote/private:$label-$version)
[ $? -ne 0 ] \
&& echo "$out" \
&& echo "β›” Docker push command failed!" \
&& exit 1

echo "😎 PUSHED $image"
image=$(docker image ls | grep "$label\-$version " | tr -s ' ' | cut -d' ' -f 1,2,3)
echo "😎 PUSHED IMAGE: $image"
17 changes: 5 additions & 12 deletions Docker/run
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
#!/bin/bash
project=Wishlist
version=$1
mode=$2
label=$(echo "$project" | tr "[:upper:]" "[:lower:]")

echo

if [[ ! -d "./$project.xcodeproj" ]] ; then
echo "πŸ€” Script must be run in project directory ..."; exit 1
fi
if [[ ! $version =~ ^[0-9]+(\.[0-9]+){2,2}(\-RC[0-9]+){0,1}$ ]];
then
echo "πŸ€” Script must be run with version number as first argument ..."; exit 1
fi
if [[ ! $mode =~ ^prod|dev$ ]] ; then
echo "πŸ€” Script must be run with mode (prod, dev) as second argument ..."; exit 1
fi
source "./Docker/functions"
check_version_and_mode

echo "🐳 RUNNING Docker compose for project $project with version $version in $mode"

APPVERSION=$version APPENV=$mode DBHOST=db docker-compose -p $label -f Docker/docker-compose up -d db
sleep 10s
APPVERSION=$version APPENV=$mode DBHOST=db docker-compose -p $label -f Docker/docker-compose up
21 changes: 5 additions & 16 deletions Docker/tag
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,20 @@
project=Wishlist
version=$1
label=$(echo "$project" | tr "[:upper:]" "[:lower:]")

echo
source "./Docker/functions"
check_version

if [[ ! -d "./$project.xcodeproj" ]] ; then
echo "πŸ€” Script must be run in project directory ..."; exit 1
fi
if [[ ! $version =~ ^[0-9]+(\.[0-9]+){2,2}(\-RC[0-9]+){0,1}$ ]];
then
echo "πŸ€” Script must be run with version number as argument ..."; exit 1
fi

echo "🐳 TAGGING Docker image for project $project with version $version"
echo "🐳 TAGGING IMAGE: Project $project with version $version"

image=$(docker image ls | grep " $version " | tr -s ' ' | cut -d' ' -f 3)
[ -z "$image" ] \
&& echo "β›” Image not found for version $version!" \
&& echo "πŸ’‘ Run build command first ..." \
&& exit 1
check_image "$version"

docker tag $image yamanote/private:$label-$version
[ $? -ne 0 ] \
&& echo "β›” Docker tag command failed!" \
&& exit 1

image=$(docker image ls | grep "$label\-$version " | tr -s ' ' | cut -d' ' -f 1,2,3)
echo "😎 TAGGED $image"
echo "😎 TAGGED IMAGE: $image"

exit 0
56 changes: 37 additions & 19 deletions Docker/test
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,47 @@
project=Wishlist
version=$1
label=$(echo "$project" | tr "[:upper:]" "[:lower:]")

echo
source "./Docker/functions"
check_version

docker_build_swift

if [[ ! -d "./$project.xcodeproj" ]] ; then
echo "πŸ€” Script must be run in project directory ..."; exit 1
fi
if [[ ! $version =~ ^[0-9]+(\.[0-9]+){2,2}(\-RC[0-9]+){0,1}$ ]];
then
echo "πŸ€” Script must be run with version number as argument ..."; exit 1
fi
echo "🐳 RUNNING TESTS: Project $project with version $version"

echo "🐳 BUILDING Docker TEST image for project $project with version $version"
docker_compose_in="$(cat <<-EOF
version: "3.3"
services:
app-test:
container_name: wishlist-app-test
command: sh -c 'swift build --configuration debug -Xswiftc "-suppress-warnings" -Xswiftc "-g" --build-path "./.build_docker_test" && swift test --skip-update --build-path "./.build_docker_test"'
image: "wishlist:swift"
environment:
SITE_URL: "http://localhost:8080"
SITE_RELEASE: "beta"
SITE_ACCESS: "all"
DBHOST: "db-test"
working_dir: /app
volumes:
- ./:/app
links:
- db-test
depends_on:
- db-test
db-test:
container_name: wishlist-db-test
image: mysql:5
environment:
MYSQL_ROOT_PASSWORD: wishlist
MYSQL_USER: wishlist
MYSQL_PASSWORD: wishlist
MYSQL_DATABASE: wishlist
EOF
)"

out=$(docker build -f Docker/docker.test -t "$label:$version-test" . 2>&1)
echo "$docker_compose_in" | APPVERSION=$version docker-compose -p $label -f - up --abort-on-container-exit
[ $? -ne 0 ] \
&& echo "$out" \
&& echo "β›” Docker build command failed!" \
&& echo "β›” Docker compose command failed!" \
&& exit 1

image=$(docker image ls | grep " $version-test " | tr -s ' ' | cut -d' ' -f 1,2,3)
echo "😎 BUILD $image"

echo "🐳 RUNNING Docker TEST compose for project $project with version $version"

SOURCE=`pwd` APPVERSION=$version DBHOST=db-test docker-compose -p $label -f Docker/docker-compose.test up
#--abort-on-container-exit
echo "😎 RUN TESTS: Project $project with version $version"
9 changes: 9 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@
"version": "3.3.1"
}
},
{
"package": "OpenSSL",
"repositoryURL": "https://github.com/IBM-Swift/OpenSSL.git",
"state": {
"branch": null,
"revision": "6c7e2e3610037fbc05c0d846cec981518961d8bf",
"version": "2.2.2"
}
},
{
"package": "Routing",
"repositoryURL": "https://github.com/vapor/routing.git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ struct VaporImageStoreProvider: ImageStoreProvider {

func removeImage(at locator: ImageStoreLocator) throws {
let imageFileMiddleware = try container.make(ImageFileMiddleware.self)
let imageFileLocator = try imageFileMiddleware.imageFileLocator(from: locator.url)
let imageFileLocator = try imageFileMiddleware.imageFileLocator(
from: locator.url,
isRelative: true
)
try imageFileMiddleware.removeFile(
at: imageFileLocator,
deleteParentsIfEmpty: true,
Expand Down
Loading

0 comments on commit 47f197a

Please sign in to comment.