Skip to content

Application CI/CD Architecture: Variables, Secrets, and Reusable Modules

Interactive Diagram

새 탭 ↗

This post covers the design and implementation of a pipeline for continuous integration and delivery of cloud-native applications. Building on the technical requirements identified during the Discovery phase, the goal is to establish an automated build/test/deploy process that produces a stable and efficient Application Service. Rather than rehashing general CI/CD concepts, the focus here is on an actual build based on GitHub Actions and Argo CD.

Pipeline design and execution can vary widely depending on the Git repository layout and branching strategy, so it’s important to design the pipeline around the development team’s actual requirements. In this project, the default branch of the Git repository was set to develop, and a GitHub Flow-based pipeline was applied on top of it.

  • On a feature branch run, Unit/Module tests are executed against the development code, and output is provided so the results can be reviewed.
  • On a develop branch run, the Container image is built and deployed via GitOps, and a Smoke Test confirms that everything is working correctly.

Application Pipeline flow by branch

Sequence diagram describing the CI/CD pipeline execution from a developer’s perspective:

Sequence Diagram

We use the Variables & Secrets features that GitHub Actions provides out of the box.

Variables are used to define values that can be reused across multiple places in a workflow. They let you manage values without hardcoding them into workflow files, and are well suited for environment-specific values or values that change frequently.

Variables can be defined at four scopes:

  • Repository scope: available to every workflow in that repository
  • Environment scope: values scoped to a specific environment (dev, prd)
  • Workflow scope: defined in code inside a .yml file under .github/workflows/
  • Organization scope: defined at the org level and shared across multiple repositories

Example of using a repository-scoped variable:

- name: Deploy java app
uses: ./.github/workflows/actions/deploy-azurecli-vm
with:
environment: "${{ inputs.environment }}"
azure-resource-prefix: "${{ vars.AZURE_RESOURCE_PREFIX }}"
vm-prefix: "${{ vars.AZURE_VM_PREFIX }}"
vm-user: "${{ vars.AZURE_VM_USER }}"
app-name: "${{ vars.APP_NAME }}"

Variables can be configured through the GitHub web UI under Repository Settings > Secrets and variables > Actions > Variables, or via the GitHub CLI.

The Secrets feature is used to protect sensitive information that requires security (API keys, passwords, auth tokens, and anything else that should never be exposed) so it can be used safely inside a GitHub Actions workflow.

Secrets can also be defined at Repository / Environment / Organization scope, and are referenced safely inside a workflow file as ${{ secrets.SECRET_NAME }}.

- name: Deploy java app
uses: ./.github/workflows/actions/deploy-azurecli-vm
with:
environment: "${{ inputs.environment }}"
azure-credentials: "${{ secrets.AZURE_CREDENTIALS_DEV }}"
gh-admin-token: "${{ secrets.GH_ADMIN_TOKEN }}"

GitHub Custom Actions are actions you write yourself to run custom jobs inside a workflow, and they let you share pipeline workflows that can be reused across the org. Jobs can be built as a Docker Container, JavaScript, or Composite Action, and each requires a metadata file that defines its input/output/entrypoint.

Composite actions let you combine multiple workflow steps within a single Job. You can bundle several commands into one Job and then reference that Job as a single step in a workflow.

Here’s an example within the same github org that sets up both a custom actions workflow and the workflow that calls it. After creating a repository for the callable workflow, write an action.yml (the file must be named either action.yml or action.yaml).

- name: Integration Java application
description: Integration Java Application using maven, azurecli and blob
inputs:
gh-admin-token:
required: true
default: ""
azure-credentials:
required: true
default: ""
storage-account:
required: true
default: ""
storage-container:
required: true
default: ""
app-name:
required: true
default: ""
runs:
using: "composite"
steps:
- name: Check out the repo
uses: actions/checkout@v4.1.7
with:
token: ${{ inputs.gh-admin-token }}
fetch-depth: 1
- name: Configure maven settings.xml
run: |
cat <<EOF > ./settings.xml
<settings>
<servers>
<server>
<id>github</id>
<username>${{ github.actor }}</username>
<password>${{ inputs.gh-admin-token }}</password>
</server>
</servers>
</settings>
EOF
shell: bash
- name: Package artifact file
run: mvn -B -DskipTests package --file ./pom.xml -s ./settings.xml
shell: bash
- name: Log in to Azure CLI
env:
AZURE_CREDENTIALS: ${{ inputs.azure-credentials }}
run: |
echo "$AZURE_CREDENTIALS" > azure_credentials.json
az login \
--service-principal \
--username $(jq -r .clientId azure_credentials.json) \
-p=$(jq -r .clientSecret azure_credentials.json) \
--tenant $(jq -r .tenantId azure_credentials.json)
az account set --subscription $(jq -r .subscriptionId azure_credentials.json)
shell: bash
- name: Upload war file to Object Storage
run: |
az storage blob upload \
--account-name ${{ inputs.storage-account }} \
--container-name ${{ inputs.storage-container }} \
--file ./target/*.war \
--name ${{ inputs.app-name }}.war \
--overwrite \
--auth-mode login
shell: bash

To use the custom action from a calling workflow, you need the right permissions, and the usage takes the form uses: [owner]/[repository]@[branch].

jobs:
build:
name: (${{ inputs.environment }}) Build using maven
runs-on: "${{ inputs.runner }}"
steps:
- name: Integration Java application
uses: example-org/integration-maven-azurecli-blob-vm@main
with:
gh-admin-token: "${{ secrets.GH_ADMIN_TOKEN }}"
azure-credentials-common: "${{ secrets.AZURE_CREDENTIALS_COMMON }}"
azure-common-storage-account: "${{ vars.AZURE_COMMON_STORAGE_ACCOUNT }}"
azure-common-artifact-container: "${{ vars.AZURE_COMMON_ARTIFACT_CONTAINER }}"
app-name: "${{ vars.APP_NAME }}"

Because this project couldn’t use Enterprise GitHub for security reasons and had to rely on the Public GitHub Free plan, we weren’t able to use the job/workflow sharing capability that only works between private repositories under an Enterprise account. If the GitHub Organization is on an Enterprise account, you can grant a workflow access to a private repository that contains jobs or reusable workflows, letting you share Jobs and Workflows internally within the Enterprise without publishing them publicly.

Continue with GitHub Actions CI Workflow: Build Caching and Image Builds.