This comprehensive guide covers the implementation of Akvo's composite actions, a collection of reusable GitHub Actions workflows designed to optimize the CI/CD pipeline. These composite actions offer standardized and tested solutions for essential development operations, including Docker container management, Kubernetes deployments, Node.js tasks, and remote server management via SSH.
By following this guide, you can integrate these pre-built actions into your workflows, ensuring consistent and reliable deployment practices while minimizing boilerplate code and configuration errors. The composite actions are centrally maintained and version-controlled, enabling seamless updates and standardization across multiple projects.
- Docker Operations
- Kubernetes Operations
- Node.js Operations
- SSH Operations
- How to Implement Composite Actions
Location: .github/actions/docker-build/action.yml
Builds a Docker image with specified parameters.
app-name: Application nameservice-name: Service namedockerfile-location: Location of Dockerfilecluster-name: Cluster name
- uses: ./composite-actions/.github/actions/docker-build
with:
app-name: 'my-app'
service-name: 'backend'
dockerfile-location: './src/Dockerfile'
cluster-name: 'production'Location: .github/actions/docker-push/action.yml
Pushes a Docker image to Google Container Registry.
app-name: Application nameservice-name: Service namegcloud-sa: Google Cloud Service Account credentialscluster-name: Cluster name
- uses: ./composite-actions/.github/actions/docker-push
with:
app-name: 'my-app'
service-name: 'backend'
gcloud-sa: ${{ secrets.GCLOUD_SERVICE_ACCOUNT }}
cluster-name: 'production'Location: .github/actions/k8s-restart/action.yml
Restarts a Kubernetes deployment.
deployment-name: Name of the deployment to restartcluster-name: Cluster namegcloud-sa: Google Cloud Service Account credentialsnamespace-name: Kubernetes namespace
- uses: ./composite-actions/.github/actions/k8s-restart
with:
deployment-name: 'my-deployment'
cluster-name: 'production'
gcloud-sa: ${{ secrets.GCLOUD_SERVICE_ACCOUNT }}
namespace-name: 'default'Location: .github/actions/k8s-rollout/action.yml
Updates a Kubernetes deployment with a new image version.
app-name: Application namedeployment-name: Deployment namecluster-name: Cluster namegcloud-sa: Google Cloud Service Account credentialsnamespace-name: Kubernetes namespacecontainer-name: Container name
- uses: ./composite-actions/.github/actions/k8s-rollout
with:
app-name: 'my-app'
deployment-name: 'my-deployment'
cluster-name: 'production'
gcloud-sa: ${{ secrets.GCLOUD_SERVICE_ACCOUNT }}
namespace-name: 'default'
container-name: 'main-container'Location: .github/actions/node-operation/action.yml
Executes Node.js commands in a containerized environment.
node-version: Node.js versionnode-command: Command to execute
- uses: ./composite-actions/.github/actions/node-operation
with:
node-version: '18'
node-command: 'npm run test'Location: .github/actions/npm-operation/action.yml
Executes NPM commands in a containerized environment.
node-version: Node.js versionnpm-command: NPM command to execute
- uses: ./composite-actions/.github/actions/npm-operation
with:
node-version: '18'
npm-command: 'install --production'Location: .github/actions/yarn-operation/action.yml
Runs Yarn install and build commands.
- uses: ./composite-actions/.github/actions/yarn-operationLocation: .github/actions/ssh-command/action.yml
Executes commands on a remote server via SSH.
server-ip: Server IP addressserver-ssh-port: SSH portserver-ssh-secret-key: SSH private keyserver-ssh-user: SSH usernamecommand: Command to execute
- uses: ./composite-actions/.github/actions/ssh-command
with:
server-ip: '192.168.1.100'
server-ssh-port: '22'
server-ssh-secret-key: ${{ secrets.SSH_PRIVATE_KEY }}
server-ssh-user: 'ubuntu'
command: 'ls -la'Location: .github/actions/ssh-docker-compose/action.yml
Pulls latest code and rebuilds/restarts Docker Compose services on a remote server.
server-ip: Server IP addressserver-ssh-port: SSH portserver-ssh-secret-key: SSH private keyserver-ssh-user: SSH usernamedocker-compose-file: Docker Compose file location
- uses: ./composite-actions/.github/actions/ssh-docker-compose
with:
server-ip: '192.168.1.100'
server-ssh-port: '22'
server-ssh-secret-key: ${{ secrets.SSH_PRIVATE_KEY }}
server-ssh-user: 'ubuntu'
docker-compose-file: './docker-compose.yml'- All actions require appropriate permissions and credentials to be set up in your GitHub repository secrets.
- Google Cloud operations require a valid service account with appropriate permissions.
- SSH operations require valid SSH credentials and proper network access to the target servers.
- Docker operations assume Docker is installed and properly configured in the environment.
Most scripts include error handling with:
set -e: Exits on first errorset -u: Errors on undefined variablesset -x: Prints commands before execution (useful for debugging)
- Always use secrets for sensitive information
- Use specific versions for base images
- Implement proper access controls
- Regularly update dependencies
- Follow the principle of least privilege
For more information about individual scripts and their specific implementations, refer to the script files in the helpers/ directory.
- GitHub repository with your application code
- GitHub Personal Access Token (PAT) with
repoaccess - The PAT stored as
GH_PATin your repository secrets
Create a new workflow file (e.g., .github/workflows/deploy.yml) in your repository.
Add the following checkout configuration that includes two checkouts:
- Main repository checkout to
srcdirectory - Composite actions checkout to
composite-actionsdirectory
jobs:
deploy:
runs-on: ubuntu-latest
environment: Test
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: src
- name: Checkout Akvo composite actions
uses: actions/checkout@v4
with:
repository: akvo/composite-actions
token: ${{ secrets.GH\_PAT }}
path: composite-actions
ref: 0.0.9After the checkouts, you can use any of the available composite actions:
Example using Docker Build action
- uses: ./composite-actions/.github/actions/docker-build
with:
app-name: 'your-app'
service-name: 'your-service'
dockerfile-location: './src/Dockerfile'
cluster-name: 'your-cluster'You can use any of these actions after the checkouts:
docker-builddocker-pushk8s-restartk8s-rolloutnode-operationnpm-operationyarn-operationssh-commandssh-docker-composersync-to-server
- Ensure your PAT has necessary permissions
- All paths in your workflow should reference the correct directory structure
- Use appropriate environment variables and secrets