Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/automa-backend-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: Run `AutomaBackend` Tests
on:
pull_request:
paths:
- 'Backend/**/*.swift'

- "Backend/**/*.swift"

jobs:
unit-tests:
Expand All @@ -14,7 +13,7 @@ jobs:

- uses: SwiftyLab/setup-swift@latest
with:
swift-version: "6.1"
swift-version: "6.1"

- uses: useblacksmith/cache@v5
with:
Expand All @@ -27,6 +26,7 @@ jobs:
compose: "false"
working-directory: "Backend"
swift_test_extra_args: "--filter '.*UnitTests.*'"
gh_pat: ${{ secrets.GET_AUTOMA_UTILITIES_GH_PAT }}

integration-tests:
runs-on: blacksmith-4vcpu-ubuntu-2404
Expand All @@ -35,13 +35,12 @@ jobs:

- uses: SwiftyLab/setup-swift@latest
with:
swift-version: "6.1"
swift-version: "6.1"

- uses: useblacksmith/cache@v5
with:
path: Backend/.build
key: ${{ runner.os }}-backend-integrationtests-${{ hashFiles('**/Package.resolved') }}

- name: Run Integration Tests
uses: GetAutomaApp/opensource-actions/swifttesting@main
with:
Expand All @@ -50,6 +49,7 @@ jobs:
swift_test_extra_args: "--filter '.*IntegrationTests.*'"
required_healthy_services_docker_compose: '["postgres", "localstack"]'
compose_services_to_startup: '["postgres", "localstack"]'
gh_pat: ${{ secrets.GET_AUTOMA_UTILITIES_GH_PAT }}
env:
OWNER: ${{ secrets.OWNER }}
REPO: ${{ secrets.REPO }}
Expand Down
1 change: 1 addition & 0 deletions Backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ db.sqlite
! .env.example
.vscode
.fly.toml
infra/docker-secrets/*
6 changes: 1 addition & 5 deletions Backend/DataTypes/Sources/DataTypes/GenericErrors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public enum GenericErrors: String, Error, Decodable, Encodable {
/// Error related to Alamofire networking operations
case alamofireError
/// Error when sending a Discord webhook message fails
case discordWebhookMessageFailed
/// Error when response decoding fails
case failedToDecodeResponse
/// Error when response encoding fails
case failedToEncodeResponse
Expand Down Expand Up @@ -61,12 +59,10 @@ public enum GenericErrors: String, Error, Decodable, Encodable {
"You're Authentication Token is Invalid!"
case .invalidUserId:
"You're UserID isn't a valid UUID. We're Investigating"
case .discordWebhookMessageFailed:
"Sorry, We couldn't send a message through the discord webhook"
case .smsMessageFailed:
"We are having some technical difficulties sending sms messages!"
case .missingImage:
""
"Image generation was unsuccessful"
case .failedToDecodeResponse:
"An Invalid Response Object was sent down to the client!"
case .failedToEncodeResponse:
Expand Down
6 changes: 6 additions & 0 deletions Backend/DevDockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ WORKDIR /app

EXPOSE 8080

EXPOSE 6834

RUN --mount=type=secret,id=GITHUB_SSH_AUTHENTICATION_TOKEN \
TOKEN=$(cat /run/secrets/GITHUB_SSH_AUTHENTICATION_TOKEN) && \
git config --global url."https://x-access-token:${TOKEN}@github.com/".insteadOf "https://github.com/"

CMD bash -c "nodemon -w ./ -w .env -e '.' --ignore ./.build --exec 'swift run App --env local $RUN_COMMAND'"
37 changes: 22 additions & 15 deletions Backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ FROM swift:6.1.0-jammy AS build

# Install OS updates
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
&& apt-get -q update \
&& apt-get -q dist-upgrade -y \
&& apt-get install -y libjemalloc-dev \
&& apt-get install -y openssl libssl-dev
&& apt-get -q update \
&& apt-get -q dist-upgrade -y \
&& apt-get install -y libjemalloc-dev \
&& apt-get install -y openssl libssl-dev

# Set up a build area
WORKDIR /build
Expand All @@ -18,6 +18,10 @@ WORKDIR /build
# as long as your Package.swift/Package.resolved
# files do not change.

RUN --mount=type=secret,id=GITHUB_SSH_AUTHENTICATION_TOKEN \
TOKEN=$(cat /run/secrets/GITHUB_SSH_AUTHENTICATION_TOKEN) && \
git config --global url."https://x-access-token:${TOKEN}@github.com/".insteadOf "https://github.com/"

COPY Package.swift .
COPY Package.resolved .

Expand All @@ -29,8 +33,8 @@ COPY . .
# Build everything, with optimizations, with static linking, and using jemalloc
# N.B.: The static version of jemalloc is incompatible with the static Swift runtime.
RUN --mount=type=cache,target=/build/.build swift build -c release \
--static-swift-stdlib \
-Xlinker -ljemalloc
--static-swift-stdlib \
-Xlinker -ljemalloc

# Switch to the staging area
WORKDIR /staging
Expand All @@ -56,15 +60,15 @@ 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 \
libjemalloc2 \
ca-certificates \
tzdata \
&& apt-get install bash \
&& apt-get install -y openssl libssl-dev libcurl4 libxml2 \
&& rm -r /var/lib/apt/lists/*
&& apt-get -q update \
&& apt-get -q dist-upgrade -y \
&& apt-get -q install -y \
libjemalloc2 \
ca-certificates \
tzdata \
&& apt-get install bash \
&& apt-get install -y openssl libssl-dev libcurl4 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
Expand All @@ -84,4 +88,7 @@ USER vapor:vapor
# Let Docker bind to port 8080
EXPOSE 8080

# Expose PrometheusService server port
EXPOSE 6834

CMD /bin/bash -c "eval './App $RUN_COMMAND'"
40 changes: 29 additions & 11 deletions Backend/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Backend/Package.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// swift-tools-version:6.0
import PackageDescription

/// INitializes Package
/// Initializes Package
public let package = Package(
name: "Backend",
platforms: [
Expand Down
2 changes: 2 additions & 0 deletions Backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1. Create `./infra/docker-secrets/` directory with the following files and secrets:
1. "GITHUB_SSH_AUTHENTICATION_TOKEN": A Github fine-grained token that allows cloning AutomaUtilities repository (private)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// AutomaWebCoreClient.swift
// Copyright (c) 2025 GetAutomaApp
// All source code and related assets are the property of GetAutomaApp.
// All rights reserved.

import AutomaUtilities
import Vapor

internal struct AutomaWebCoreClient {
private let client: any Client
private let baseURL: URL

public init(client: any Client) throws {

Check warning on line 13 in Backend/Sources/App/Clients/AutomaWebCoreClient/AutomaWebCoreClient.swift

View workflow job for this annotation

GitHub Actions / swiftlint

public declarations should be documented (missing_docs)
self.client = client
let urlString = try Environment.getOrThrow("AUTOMA_WEB_CORE_API_BASE_URL")
baseURL = try URL.fromString(payload: .init(string: urlString))
}

public func getWebsiteHTML(payload: AutomaWebCoreAPIEndpointPayload) async throws -> String {

Check warning on line 19 in Backend/Sources/App/Clients/AutomaWebCoreClient/AutomaWebCoreClient.swift

View workflow job for this annotation

GitHub Actions / swiftlint

public declarations should be documented (missing_docs)
let res = try await client.get("\(baseURL.absoluteString)/api") { req in
try req.content.encode(payload)
}
return try res.content.decode(String.self)
}
}

This file was deleted.

This file was deleted.

Loading
Loading