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

Create GitHub Action Workflow to build sdks and test server #16

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
61 changes: 61 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
collect_sdks:
runs-on: ubuntu-latest
outputs:
sdks: ${{ steps.sdks.outputs.sdks }}
steps:
- uses: actions/checkout@v4
- id: sdks
run: echo "sdks=$(cd sdks && ls -d * | jq --raw-input --slurp --compact-output 'split("\n")[:-1]')" >> ${GITHUB_OUTPUT}

build:
runs-on: ubuntu-latest
needs: collect_sdks
strategy:
matrix:
sdks: ${{ fromJson(needs.collect_sdks.outputs.sdks) }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build SDK Docker Images
uses: docker/build-push-action@v6
with:
context: sdks/${{ matrix.sdks }}
push: false

battle:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Find and Replace host network
uses: jacobtomlinson/gha-find-replace@v3
with:
find: "host"
replace: "bridge"
include: "docker-compose.yml"

- name: Build Docker Compose Services
run: docker compose build

- name: Run Docker Compose
run: docker compose --profile battle up battle-server

- name: Tear Down Docker Compose
if: always()
run: docker compose down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ game-log.txt
test-log.txt
sdks/clojure/target
.vscode

.fake
31 changes: 31 additions & 0 deletions Docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Running the Clients with Docker Compose

__Note__: In base directory ->
```
docker compose up
```

Run Server (see above)

# Running the Server with Docker

```
docker buildx build -f server/Dockerfile server/ -t server
```

```
docker run --network=host server
```
__Note__: This assumes you have two clients running on localhost using post 9091 and 9092.

# Run Single Player and Server with Docker compose

```
docker compose --profile single-player up server
```

# Run Two Players and Server with Docker compose

```
docker compose --profile battle up battle-server
```
36 changes: 35 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,49 @@ version: '3.8'
services:
p1:
build:
context: sdks/java
context: sdks/ruby
dockerfile: Dockerfile
ports:
- "9091:9090"
networks:
- app-network

p2:
build:
context: sdks/ruby
dockerfile: Dockerfile
ports:
- "9092:9090"
depends_on:
- p1
networks:
- app-network

server:
build:
context: server
dockerfile: Dockerfile
command: ["ruby", "src/app.rb", "-nu", "-f", "-p1p", "9090", "-p1", "p1"]
depends_on:
- p1
networks:
- app-network
profiles:
- single-player

battle-server:
build:
context: server
dockerfile: Dockerfile
command: ["ruby", "src/app.rb", "-nu", "-f", "-p1p", "9090", "-p1", "p1", "-p2p", "9090", "-p2", "p2" ]
depends_on:
- p2
networks:
- app-network
profiles:
- battle

networks:
app-network:
driver: host

2 changes: 1 addition & 1 deletion server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ COPY Gemfile Gemfile
RUN bundle install

COPY . .
CMD ["ruby", "src/app.rb", "-nu", "-f", "-p1p", "9091", "-p1", "127.0.0.1", "-p2p", "9092", "-p2", "127.0.0.1" ]
CMD ["ruby", "src/app.rb", "-nu", "-f", "-p1p", "9091", "-p1", "localhost", "-p2p", "9092", "-p2", "localhost" ]