DEV Community

netcell
netcell

Posted on • Originally published at netcell.netlify.com on

Developing GameClosure with Docker and Gitlab CI

Develop games with HTML5 game framework GameClosure using Docker and Gitlab CI.

Docker for Development

Following the guide of GameClosure, I made a Dockerfile that has gameclosure/devkit installed where I copied manifest.json, package.json and run the commands to install dependencies :

COPY --chown=node manifest.json package.json ./
    RUN devkit install
    COPY --chown=node ./package.json ./
    RUN npm install
    CMD ["devkit", "serve"]
Enter fullscreen mode Exit fullscreen mode

My project only needs 2 folders: src for source codes and resources for assets. These are the folders required by GameClosure, everything else are dependencies and installed in the docker image. Using docker-compose, I mount these folders to the container and expose port 9200.

volumes:
        - ./src:/home/node/game/src
        - ./resources:/home/node/game/resources
    ports:
        - 9200:9200
Enter fullscreen mode Exit fullscreen mode

From the host machine, I can access devkit page via browser at localhost:9200 as normal.

Continous Deployment

In order to build the project, I need another docker-compose configuration to mount a build folder and run the build command instead of serve.

volumes:
        - ./build:/home/node/game/build
    command: devkit debug browser-mobile
Enter fullscreen mode Exit fullscreen mode

I didn’t want to build the game manually, so I used Gitlab CI/CD service to have it runs the container, builds the game and deploys to Gitlab Pages for me. I create this .gitlab-ci.yml file with pages job that build the game into *public* artifacts:

Unlike Github Pages which can only build Jekyll, Gitlab Pages can automatically build almost anything with its CI/CD service.

pages:
        stage: deploy
        script:
            - docker-compose -f docker-compose.yml -f docker-compose.browser-mobile.yml up
            - cp -a build/debug/browser-mobile/. public/
        artifacts:
            paths:
                - public
Enter fullscreen mode Exit fullscreen mode

Now, everytime I push to my Gitlab repository, the game will be built and served at Gitlab Pages.

Top comments (0)