Uploading files to hosting from automated builds

If you compile your game using automatic builds, make the uploading of files to VK hosting a step in your build process. This will help speed up the publication of new versions and reduce manual actions.

To automate file upload, use the vk-miniapps-deploy library.

Step 1. Install library and prepare the access token

  1. 1.

    On the computer you'll be using to upload files, do the following:

    • •

      Install the vk-miniapps-deploy library.

    • •

      Prepare the game and configuration files.

    • •

      Manually upload the game files to the hosting.

    For more details, see Static hosting for games.

  2. 2.

    Before uploading the files, the library will generate a special access token MINI_APPS_ACCESS_TOKEN and display it in the command line window.

    This token is required to automatically upload files. Copy it.

    The token can also be obtained through other methods.

  3. 3.

    Create an environment variable named MINI_APPS_ACCESS_TOKEN and assign it the value of the token. The steps for creating the variable depend on the operating system you're using.

    For example:

    • •

      On Windows, you can set the variable like this:

      Command line
      set MINI_APPS_ACCESS_TOKEN=<token-value>
    • •

      On MacOS and Linux, you can specify the variable as part of the run command:

      Command line
      $ env MINI_APPS_ACCESS_TOKEN=<token-value> yarn deploy

Other ways to get the token

Method 1

You can find the token in the following file on your hard drive:

  • •

    On Windows: C:\Users\.config\configstore\@vkontakte\vk-miniapps-deploy.json

  • •

    On macOS and Linux: ~/.config/configstore/@vkontakte/vk-miniapps-deploy.json

Method 2

Copy the token from your game settings: Development → Access keys → Service token value.

Step 2. Configure upload parameters

When uploading files to hosting, the library requests information from the user in the command line. This behavior isn't suitable for automated builds since they don't involve user interaction.

To disable these requests, add the "noprompt": 1 parameter to the vk-hosting-config.json file.

vk-hosting-config.json
{ "static_path": "build", "app_id": 123456, "endpoints": { "mobile": "index_DG.html", "web": "index.html", "mvk": "index.html" }, "noprompt": 1 }

After that, the library will use the default responses. During manual upload, these options are shown in uppercase letters in the command line window.

Default responsesDefault responses

If the default responses don't suit your needs, you can adjust the upload parameters using environment variables.

Step 3. Prepare build and files

  1. 1.

    Prepare the build script. It must copy the final files into a single folder, such as build.

  2. 2.

    Make sure this folder is specified in the static_path field of the vk-hosting-config.json file.

Step 4. Add a run command

To upload files to the hosting, add the following line to your automated build script:

Command line
npm run deploy

Your automatic build is ready to upload files to the hosting.

Environment variables

To configure upload parameters for automated builds, use environment variables.

Assign values to these variables before executing the upload command. This is done differently on Windows and macOS. Refer to your operating system documentation for details.

Variable
Description
MINI_APPS_APP_ID
Game identifier. Use this variable as an equivalent to the app_id value, located in the vk-hosting-config.json configuration file.
MINI_APPS_ENVIRONMENT
Indicates which URLs in the game settings need to be updated when files are uploaded. Possible values:    • production — update production URLs (those used by users to launch the game) and development URLs.    • dev — only update development URLs. The library requests a confirmation code when updating production URLs.
HTTP_PROXY, HTTPS_PROXY
Makes it possible to execute all API requests via a specified proxy server.

Special considerations

When updating production URLs, the library sends a confirmation code to the game's main administrator and requests its input. The URLs will only change after providing the correct code.

If only dev URLs are updated, no confirmation is required.

See more