The Swift Server Group recently published a set of deployment guidelines tailored for various instances, services, and cloud providers. To deploy a Vapor application., follow the breadcrumbs I provide below.
I opted for the AWS-copilot-fargate-vapor-mongo guide (note the discrepancy between the title and my linked keyword). I'll detail my process of deploying a custom service, but using Postgres as the storage type.
$ download code
AWS Copilot with Fargate
I believe the goal of a blog post is to offer some of the caveats that the documentation hides. As a result, to build an app with AWS copilot CLI go to https://aws.github.io/copilot-cli/
Internals
I choose to use PostgreSQL for my backend application and the Fluent ORM. On the AWS side, this is Aurora Serverless RDS.
The Environment.APICLUSTER_SECRET that the storage infra type sets for you have the following structure (This is a Swift struct from a string/data)
struct APICluster: Codable {
var dbClusterIdentifier: String
var password: String
var dbname: String
var engine: String
var port: Int
var host: String
var username: String
}
You will get this type at runtime, in contrast to how these values get configured if you were to use MongoDB. You will need to inject the MongoDB values in the pre-packaging phase.
CI/CD with Docker
A site I used as a reference tmac's SPM posts
You will get this type at runtime, in contrast to how these values get configured if you use MongoDB. You will need to inject the MongoDB values in the pre-packaging phase.
In my local, I* run
docker build --ssh github=$HOME/.ssh/id_ed25519 -t idelfonsog2/stranded-api .
docker tag idelfonsog2/stranded-api:latest ${{ secrets.ECR_REPO_URL }}
docker push ${{ secrets.ECR_REPO_URL }}
In GitHub Action, it* runs.
- name: Build Docker Image
run: |
docker build --ssh github=$HOME/.ssh/id_ed25519 -t idelfonsog2/stranded-api .
docker tag idelfonsog2/stranded-api:latest ${{ secrets.ECR_REPO_URL }}
docker push ${{ secrets.ECR_REPO_URL }}
- uses: ksivamuthu/aws-copilot-github-action@v0.0.1
with:
command: install
- name: Copilot Deploy
run: |
copilot svc deploy --name api --app stranded --env dev
Freebie:
convert the following file to .yaml
Edit the Build Docker Image job per your image repository!
Result
I deployed my copilot application. ECS requires your service/task to have a GET / for health checks that returns a 200 status
import Vapor
...
app.get("") { _ in HTTPStatus.ok }
response:
200
Comentários