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 14 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
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 }}
43 changes: 6 additions & 37 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 @@ -26,45 +26,14 @@ Next, you need to setup the Docker container and Serverpod & Pixorama database t

```bash
cd pixorama_server
serverpod generate
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 --role maintenance
```

Finally, start the server by typing:
Expand All @@ -73,12 +42,12 @@ Finally, start the server by typing:
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:
In another window, go to pixorama_flutter and then type:

```bash
flutter run
flutter run -d Chrome
Copy link
Contributor

Choose a reason for hiding this comment

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

flutter run -d chrome

Copy link
Author

Choose a reason for hiding this comment

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

done

```
The debugger will open chrome and the server will return the following screen.
Flutter will open Chrome and start the Pixorama app.

<img width="1312" alt="image" src="https://user-images.githubusercontent.com/611808/222937342-e9d01f59-f73a-49d3-992b-c8d7560b08a1.png">

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)
25 changes: 16 additions & 9 deletions pixorama_client/lib/src/protocol/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
// 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 'protocol.dart' as _i3;
import 'protocol.dart' as _i2;

/// 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 +27,26 @@ 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,
_i2.Protocol(),
securityContext: securityContext,
authenticationKeyManager: authenticationKeyManager,
streamingConnectionTimeout: streamingConnectionTimeout,
connectionTimeout: connectionTimeout,
) {
pixorama = _EndpointPixorama(this);
pixorama = EndpointPixorama(this);
}

late final _EndpointPixorama pixorama;
late final EndpointPixorama pixorama;

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

@override
Map<String, _i1.ModuleEndpointCaller> get moduleLookup => {};
}
57 changes: 53 additions & 4 deletions pixorama_client/lib/src/protocol/image_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,28 @@
// 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:typed_data' as _i2;

class ImageData extends _i1.SerializableEntity {
ImageData({
abstract class ImageData extends _i1.SerializableEntity {
ImageData._({
this.id,
required this.pixels,
required this.width,
required this.height,
});

factory ImageData({
int? id,
required _i2.ByteData pixels,
required int width,
required int height,
}) = _ImageDataImpl;

factory ImageData.fromJson(
Map<String, dynamic> jsonSerialization,
_i1.SerializationManager serializationManager,
Expand All @@ -31,6 +40,9 @@ class ImageData extends _i1.SerializableEntity {
);
}

/// The database id, set if the object has been inserted into the
/// database or if it has been fetched from the database. Otherwise,
/// the id will be null.
int? id;

_i2.ByteData pixels;
Expand All @@ -39,13 +51,50 @@ class ImageData extends _i1.SerializableEntity {

int height;

ImageData copyWith({
int? id,
_i2.ByteData? pixels,
int? width,
int? height,
});
@override
Map<String, dynamic> toJson() {
return {
'id': id,
'pixels': pixels,
if (id != null) 'id': id,
'pixels': pixels.toJson(),
'width': width,
'height': height,
};
}
}

class _Undefined {}

class _ImageDataImpl extends ImageData {
_ImageDataImpl({
int? id,
required _i2.ByteData pixels,
required int width,
required int height,
}) : super._(
id: id,
pixels: pixels,
width: width,
height: height,
);

@override
ImageData copyWith({
Object? id = _Undefined,
_i2.ByteData? pixels,
int? width,
int? height,
}) {
return ImageData(
id: id is int? ? id : this.id,
pixels: pixels ?? this.pixels.clone(),
width: width ?? this.width,
height: height ?? this.height,
);
}
}
Loading