Skip to content

Commit

Permalink
port to dart
Browse files Browse the repository at this point in the history
  • Loading branch information
ukarim committed Oct 25, 2023
1 parent 67dfdfc commit 335eef7
Show file tree
Hide file tree
Showing 16 changed files with 1,071 additions and 802 deletions.
3 changes: 0 additions & 3 deletions .dockerignore

This file was deleted.

12 changes: 6 additions & 6 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Golang
uses: actions/setup-go@v2
- uses: actions/checkout@v3
- name: Set up Dart
uses: dart-lang/setup-dart@v1
with:
go-version: 1.16.x
- name: Run Golang tests
run: go test
sdk: 3.1
- name: Run Dart tests
run: dart pdu_test.dart

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
smscsim
*.swp

.idea/
main.exe
main
18 changes: 11 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
FROM golang:1.13.15-alpine AS build
FROM dart:3.1.3-sdk AS build

WORKDIR /app

COPY . /app

RUN apk upgrade --update \
&& apk add -U tzdata \
&& rm -rf /var/cache/apk/* \
&& go build
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata \
&& dart compile exe main.dart -o smscsim

##########################################

FROM alpine:3.12.1
FROM scratch

# copy necessary libs
COPY --from=build /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libdl.so.2
COPY --from=build /lib/x86_64-linux-gnu/libpthread.so.0 /lib/x86_64-linux-gnu/libpthread.so.0
COPY --from=build /lib/x86_64-linux-gnu/libm.so.6 /lib/x86_64-linux-gnu/libm.so.6
COPY --from=build /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6
COPY --from=build /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
COPY --from=build /usr/share/zoneinfo /usr/share/zoneinfo

# copy app itself
COPY --from=build /app/smscsim /app/smscsim

ENTRYPOINT ["/app/smscsim"]

13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ Lightweight, zero-dependency and stupid SMSc simulator.

### Usage

1) Build from sources (need golang compiler)
1) Run as dart script

```
go build
./smscsim
dart main.dart
```

2) or build docker image
2) or compile to single executable and run it

```
docker build -t smscsim .
docker run -p 2775:2775 -p 12775:12775 smscsim
dart compile exe main.dart -o smscsim
./smscsim
```

3) or build and run with docker-compose
3) or build and start with docker-compose

```
docker-compose up
Expand Down
3 changes: 0 additions & 3 deletions go.mod

This file was deleted.

26 changes: 26 additions & 0 deletions main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'dart:io';

import 'smsc.dart';
import 'web.dart';

final int DEF_SMSC_PORT = 2775;
final int DEF_WEB_PORT = 12775;

void main() {
var env = Platform.environment;
var smscPort = parseInt(env['SMSC_PORT'], DEF_SMSC_PORT);
var webPort = parseInt(env['WEB_PORT'], DEF_WEB_PORT);
var failedSubmits = parseBool(env['FAILED_SUBMITS'], false);

var smsc = SmscServer(failedSubmits);
smsc.start(smscPort);
WebServer(smsc).start(webPort);
}

int parseInt(String? n, int def) {
return int.tryParse(n ?? "$def") ?? def;
}

bool parseBool(String? b, bool def) {
return bool.tryParse(b ?? "$def") ?? def;
}
42 changes: 0 additions & 42 deletions main.go

This file was deleted.

Loading

0 comments on commit 335eef7

Please sign in to comment.