-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (52 loc) · 1.83 KB
/
docker-swarm-deploy.yml
File metadata and controls
63 lines (52 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
name: Deploy Docker Stack
on:
workflow_call:
inputs:
docker_context_name:
description: 'Docker Context Name'
required: true
type: string
docker_stack_name:
description: 'Docker Stack Name'
required: true
type: string
docker_compose_path:
description: 'Path to Docker Compose file'
required: true
type: string
docker_image_tag:
description: 'Docker image tag'
required: true
type: string
environment_variables:
description: 'Optional list of environment variables'
required: false
type: string
jobs:
deploy:
runs-on: self-hosted
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Deploy Docker Stack
run: |
# Docker context
CONTEXT_NAME="${{ inputs.docker_context_name }}"
# Docker compose file name
COMPOSE_FILE_NAME="${{ inputs.docker_compose_path }}"
# Image tag
IMAGE_TAG=${{ inputs.docker_image_tag }}
# Stack name from the $COMPOSE_FILE_NAME
COMPOSE_STACK_NAME="${{ inputs.docker_stack_name }}"
# Variables that will be substituted in the $COMPOSE_FILE_NAME
export DOCKER_TAG=$IMAGE_TAG
# Process optional environment variables
if [[ -n "${{ inputs.environment_variables }}" ]]; then
echo "${{ inputs.environment_variables }}" | while IFS= read -r env_var; do
export "$env_var"
done
fi
# Use context
docker context use $CONTEXT_NAME
# Deploy stack with a single docker-compose.yml file
docker stack config --compose-file $COMPOSE_FILE_NAME | docker stack deploy --prune --compose-file - $COMPOSE_STACK_NAME