API
The Gcore Customer Portal is being updated. Screenshots may not show the current version.
Cloud
Cloud
OverviewTerraformBilling
API
Chosen image
Home/Cloud/Container as a Service/Deploy via GitHub actions

Build and deploy containers to CaaS via GitHub actions

Overview

We've developed a public GitHub action that allows you to deploy your containers to Gcore Container as a Service directly via GitHub workflows. This action can be found in the deploy-container repository repository and in the Marketplace under GitHub Actions.

GitHub Actions

The principle of Actions is described in the detailed GitHub documentation. You create a YAML file in your repository's .github/workflows directory. This YAML file contains the code that is executed during a workflow run. Other key components of GitHub Actions include:

  • Events, which trigger workflows (e.g., pull_request)
  • Jobs, which define the steps that will be executed on the runner or actions that will be run
  • Actions, which allow you to automate, customize, and execute your software development workflows directly in your repository
  • Runners, which are servers where workflows are executed

How to use the Gcore action

1. In the .github/workflows/ directory, create a file with the .yml extension.

2. Add the following content to your .yml file:

name: Deploy

on:
  workflow_dispatch:

jobs:
  deploy:
    name: deploy
    runs-on: ubuntu-latest

    steps:
      - id: deploy
        uses: gcore-github-actions/deploy-container@v1
        with:
          api-token: ${{ secrets.GCLOUD_API_TOKEN }}
          project-id: ${{ vars.GCLOUD_PROJECT }}
          region-id: ${{ vars.GCLOUD_REGION }}
          name: my-container
          image: nginx:latest

      - name: Use output
        run: echo "${{ steps.deploy.outputs.address }}"

Complete the required and optional fields per the below.

Required fields:

  • api-token is a permanent API token that authenticates the GitHub action to Gcore API.
  • project-id is the ID of the Gcore project where the container should be deployed. You can use the list projects API request to retrieve this.
  • region-id is the ID of the region where the container should be deployed. This can be obtained using the list regions API request.
  • name is the name of the container to be deployed.
  • image in the name of the container image to be deployed (e.g., docker.io/nginx:latest.)

Optional fields:

  • listening-port is the port on which the container will be listening for network connections. The default value is 80.
  • description is a custom description of the container.
  • envs is the list of newline-separated key-value pairs to set as environment variables. For example:
with:
   envs: |
     FOO=bar
     BAZ=biz
  • flavor is the container flavor that determines the amount of memory and CPU allocated to each container instance. The default value is 80mCPU-128MB.
  • timeout is the duration in seconds that elapses before scaling down container instances. The default value is 60.
  • scale-min is the minimum number of instances to run. When set to 0, the container will scale down to zero running instances when it receives no traffic for the duration of timeout. The default value is 1.
  • scale-max is the maximum number of instances to run. The value must be greater than or equal to scale-min. The default value is 1.
  • is-disabled is the field (boolean) that controls the state of the container (on or off.) When true is set, the container is disabled; any running instances are shut down. The default value is false.
  • is-api-key-auth is the field (boolean) that enables API key authentication for the container endpoint address. You can create and assign API keys to the container in the Gcore Customer Portal. When true is set, API keys are enabled. The default value is false.
  • pull-secret is the name of the private registry credentials to use when fetching the container image. The credentials must already be configured in the Gcore Customer Portal.

3. Create a .secrets file with your GCLOUD_API_TOKEN value obtained from the Customer Portal.

4. Create a .vars file with your GCLOUD_API_URL, GCLOUD_PROJECT and GCLOUD_REGION values.

The Gcore action has the following output elements:

  • address is the endpoint address of your container.
  • status is the status of your container (e.g., Pending, Deploying, Ready, or Error.)
  • status-message is the last message associated with the current container status. This can be useful for troubleshooting deployment issues.

Was this article helpful?

Not a Gcore user yet?

Discover our offerings, including virtual instances starting from 3.7 euro/mo, bare metal servers, AI Infrastructure, load balancers, Managed Kubernetes, Function as a Service, and Centralized Logging solutions.

Go to the product page