Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebuild of pixorama for serverpod 1.2.3 #7

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 12 additions & 11 deletions .github/workflows/deployment-aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,10 @@ jobs:
with:
submodules: recursive

- name: Setup Flutter SDK
uses: flutter-actions/setup-flutter@v2
- name: Setup Dart SDK
uses: dart-lang/setup-[email protected]
with:
channel: stable
version: 3.3.2

- name: Compile Flutter web app
shell: bash
run: |
scripts/build_web
sdk: 3.0

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
Expand All @@ -51,20 +45,27 @@ jobs:
echo "$SERVERPOD_PASSWORDS" > config/passwords.yaml
ls config/

- name: Get Dart packages
working-directory: pixorama_server
run: dart pub get

- name: Compile server
working-directory: pixorama_server
run: dart compile kernel bin/main.dart

- name: Create CodeDeploy Deployment
id: deploy
env:
PROJECT_NAME: pixorama
AWS_NAME: pixorama
DEPLOYMENT_BUCKET: pixorama-deployment-564135
DEPLOYMENT_BUCKET: pixorama-deployment-5800585
TARGET: ${{ github.event.inputs.target }}
run: |
# Deploy server to AWS
TARGET="${TARGET:=${GITHUB_REF##*-}}"
echo "Deploying to target: $TARGET"
mkdir -p vendor
cp "${PROJECT_NAME}_server/aws/scripts/appspec.yml" appspec.yml
cp "${PROJECT_NAME}_server/deploy/aws/scripts/appspec.yml" appspec.yml
zip -r deployment.zip .
aws s3 cp deployment.zip "s3://${DEPLOYMENT_BUCKET}/deployment.zip"
aws deploy create-deployment \
Expand Down
99 changes: 99 additions & 0 deletions .github/workflows/deployment-gcp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Deploy to GCP
on:
push:
branches: [ deployment-gcp-production, deployment-gcp-staging ]
workflow_dispatch:
inputs:
target:
description: 'Target'
required: true
default: 'production'
type: choice
options:
- 'staging'
- 'production'

env:
# TODO: Update with your Google Cloud project id. If you have changed the
# region and zone in your Terraform configuration, you will need to change
# it here too.
PROJECT: "<PROJECT ID>"
REGION: us-central1
ZONE: us-central1-c

jobs:
deploy:
name: Deploy to Google Cloud Run
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive

- name: Setting Target Mode from Input
if: ${{ github.event.inputs.target != '' }}
run: echo "TARGET=${{ github.event.inputs.target }}" >> $GITHUB_ENV

- name: Setting Target mode based on branch
if: ${{ github.event.inputs.target == '' }}
run: echo "TARGET=${GITHUB_REF##*-}" >> $GITHUB_ENV

- name: Set repository
run: echo "REPOSITORY=serverpod-${{ env.TARGET }}-container" >> $GITHUB_ENV

- name: Set Image Name
run: echo "IMAGE_NAME=serverpod" >> $GITHUB_ENV

- name: Set Service Name
run: echo "SERVICE_NAME=$(echo $IMAGE_NAME | sed 's/[^a-zA-Z0-9]/-/g')" >> $GITHUB_ENV

- name: Test
run: echo $SERVICE_NAME


- id: "auth"
name: "Authenticate to Google Cloud"
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}"

- name: Create passwords file
working-directory: pixorama_server
shell: bash
env:
SERVERPOD_PASSWORDS: ${{ secrets.SERVERPOD_PASSWORDS }}
run: |
pwd
echo "$SERVERPOD_PASSWORDS" > config/passwords.yaml
ls config/

- name: Configure Docker
working-directory: pixorama_server
run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev

- name: Build the Docker image
working-directory: pixorama_server
run: "docker build -t $IMAGE_NAME ."

- name: Tag the Docker image
working-directory: pixorama_server
run: docker tag $IMAGE_NAME ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT }}/${{ env.REPOSITORY }}/$IMAGE_NAME

- name: Push Docker image
working-directory: pixorama_server
run: docker push ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT }}/${{ env.REPOSITORY }}/$IMAGE_NAME

# Uncomment the following code to automatically restart the servers in the
# instance group when you push a new version of your code. Before doing
# this, make sure that you have successfully deployed a first version.
#
# - name: Restart servers in instance group
# run: |
# gcloud compute instance-groups managed rolling-action replace serverpod-${{ env.TARGET }}-group \
# --project=${{ env.PROJECT }} \
# --replacement-method='substitute' \
# --max-surge=1 \
# --max-unavailable=1 \
# --zone=${{ env.ZONE }}
38 changes: 4 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For full Serverpod documentation, please visit

## Server code
On the server side there are three main files that makes Pixorama tick. Two
serializable objects, found in the [protocol](pixorama_server/lib/src/protocol)
serializable objects, found in the [generated](pixorama_server/lib/src/generated)
directory and the
[PixoramaEndpoint](pixorama_server/lib/src/endpoints/pixorama_endpoint.dart)
class. Those files are great starting points for understanding how Pixorama
Expand All @@ -28,43 +28,13 @@ Next, you need to setup the Docker container and Serverpod & Pixorama database t
cd pixorama_server
serverpod generate
saammz marked this conversation as resolved.
Show resolved Hide resolved
docker compose up --build --detach
docker compose exec -T postgres env PGPASSWORD="PASSWORD" psql -h postgres -U postgres -d pixorama < generated/tables-serverpod.pgsql
docker compose exec -T postgres env PGPASSWORD="PASSWORD" psql -h postgres -U postgres -d pixorama < generated/tables.pgsql
```
The first docker compose exec commands should return numerous sql verifications like:
```bash
CREATE TABLE
ALTER TABLE
CREATE INDEX
CREATE TABLE
ALTER TABLE
CREATE INDEX
CREATE INDEX
...
.
.
CREATE INDEX
ALTER TABLE
```

The second docker compose exec commands should return two sql verifications like:
```bash
CREATE TABLE
ALTER TABLE
```

This version of Pixorama runs the serverpod locally from the vendor directory, and postgres and redis are run within Docker containers.

```bash
cd vendor
git clone https://github.com/serverpod/serverpod.git
cd ..
```

Next, fetch packages for serverpod.
Next, run migrations by typing:

```bash
dart pub get
dart bin/main.dart --apply-migrations
saammz marked this conversation as resolved.
Show resolved Hide resolved
```

Finally, start the server by typing:
Expand All @@ -76,7 +46,7 @@ dart bin/main.dart
In another window, go to pixorama_flutter and modify the `lib/main.dart` file to use the local server url instead of the live app server. Then type:
saammz marked this conversation as resolved.
Show resolved Hide resolved

```bash
flutter run
flutter run -d chrome
```
The debugger will open chrome and the server will return the following screen.
saammz marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
5 changes: 5 additions & 0 deletions pixorama_client/dartdoc_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dartdoc:
categories:
"Endpoint":
markdown: doc/endpoint.md
name: Endpoint
15 changes: 15 additions & 0 deletions pixorama_client/doc/endpoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Callable endpoints

Each class contains callable methods that will call a method on the server side. These are normally defined in the `endpoint` directory in your server project. This client sends requests to these endpoints and returns the result.

Example usage:

```dart
// How to use ExampleEndpoint.
client.example.hello("world!");

// Generic format.
client.<endpoint>.<method>(...);
```

Please see the full official documentation [here](https://docs.serverpod.dev)
44 changes: 36 additions & 8 deletions pixorama_client/lib/src/protocol/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,36 @@
// ignore_for_file: library_private_types_in_public_api
// ignore_for_file: public_member_api_docs
// ignore_for_file: implementation_imports
// ignore_for_file: use_super_parameters
// ignore_for_file: type_literal_in_constant_pattern

// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:serverpod_client/serverpod_client.dart' as _i1;
import 'dart:io' as _i2;
import 'dart:async' as _i2;
import 'protocol.dart' as _i3;

/// {@category Endpoint}
class EndpointExample extends _i1.EndpointRef {
EndpointExample(_i1.EndpointCaller caller) : super(caller);

@override
String get name => 'example';

_i2.Future<String> hello(String name) => caller.callServerEndpoint<String>(
'example',
'hello',
{'name': name},
);
}

/// The Pixorama endpoint handles all communication related to keeping clients
/// up-to-date with the latest version of the pixel image. When a client first
/// connects, it is sent a full version of the image with the ImageData message.
/// Whenever a pixel is being edited by a client, we store the edit in the
/// _pixelData array and pass on the changes to all connected clients.
class _EndpointPixorama extends _i1.EndpointRef {
_EndpointPixorama(_i1.EndpointCaller caller) : super(caller);
/// {@category Endpoint}
class EndpointPixorama extends _i1.EndpointRef {
EndpointPixorama(_i1.EndpointCaller caller) : super(caller);

@override
String get name => 'pixorama';
Expand All @@ -25,21 +42,32 @@ class _EndpointPixorama extends _i1.EndpointRef {
class Client extends _i1.ServerpodClient {
Client(
String host, {
_i2.SecurityContext? context,
dynamic securityContext,
_i1.AuthenticationKeyManager? authenticationKeyManager,
Duration? streamingConnectionTimeout,
Duration? connectionTimeout,
}) : super(
host,
_i3.Protocol(),
context: context,
securityContext: securityContext,
authenticationKeyManager: authenticationKeyManager,
streamingConnectionTimeout: streamingConnectionTimeout,
connectionTimeout: connectionTimeout,
) {
pixorama = _EndpointPixorama(this);
example = EndpointExample(this);
pixorama = EndpointPixorama(this);
}

late final _EndpointPixorama pixorama;
late final EndpointExample example;

late final EndpointPixorama pixorama;

@override
Map<String, _i1.EndpointRef> get endpointRefLookup => {'pixorama': pixorama};
Map<String, _i1.EndpointRef> get endpointRefLookup => {
'example': example,
'pixorama': pixorama,
};

@override
Map<String, _i1.ModuleEndpointCaller> get moduleLookup => {};
}
70 changes: 70 additions & 0 deletions pixorama_client/lib/src/protocol/example.dart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should not be here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* AUTOMATICALLY GENERATED CODE DO NOT MODIFY */
/* To generate run: "serverpod generate" */

// ignore_for_file: library_private_types_in_public_api
// ignore_for_file: public_member_api_docs
// ignore_for_file: implementation_imports
// ignore_for_file: use_super_parameters
// ignore_for_file: type_literal_in_constant_pattern

// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:serverpod_client/serverpod_client.dart' as _i1;

abstract class Example extends _i1.SerializableEntity {
Example._({
required this.name,
required this.data,
});

factory Example({
required String name,
required int data,
}) = _ExampleImpl;

factory Example.fromJson(
Map<String, dynamic> jsonSerialization,
_i1.SerializationManager serializationManager,
) {
return Example(
name: serializationManager.deserialize<String>(jsonSerialization['name']),
data: serializationManager.deserialize<int>(jsonSerialization['data']),
);
}

String name;

int data;

Example copyWith({
String? name,
int? data,
});
@override
Map<String, dynamic> toJson() {
return {
'name': name,
'data': data,
};
}
}

class _ExampleImpl extends Example {
_ExampleImpl({
required String name,
required int data,
}) : super._(
name: name,
data: data,
);

@override
Example copyWith({
String? name,
int? data,
}) {
return Example(
name: name ?? this.name,
data: data ?? this.data,
);
}
}
Loading