-
Notifications
You must be signed in to change notification settings - Fork 1
96 lines (90 loc) · 3.58 KB
/
deploy.yml
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: Deploy proxy.saeon
on:
workflow_dispatch:
inputs:
stack:
required: true
description: Either 'next' (to deploy the development version) or 'stable' (to deploy to production)
default: next
type: string
env:
SWARM_HOSTNAME: ${{ secrets.SWARM_HOSTNAME }} # Organization secret
SWARM_USERNAME: ${{ secrets.SWARM_USERNAME }} # Organization secret
SWARM_PASSWORD: ${{ secrets.SWARM_PASSWORD }} # Organization secret
SWARM_SSH_PORT: ${{ secrets.SWARM_SSH_PORT }} # Organization secret
ELASTICSEARCH_NEXT_ADDRESS: ${{ secrets.ELASTICSEARCH_NEXT_ADDRESS }} # Organization secret
ELASTICSEARCH_7_14_ADDRESS: ${{ secrets.ELASTICSEARCH_7_14_ADDRESS }} # Organization secret
ELASTICSEARCH_8_X_ADDRESS: ${{ secrets.ELASTICSEARCH_8_X_ADDRESS }} # Organization secret
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REGISTRY: ghcr.io
jobs:
build:
runs-on: ubuntu-latest
env:
IMAGE_NAME: ${{ github.repository }}_node_${{ inputs.stack }}
BRANCH_REF: ${{ inputs.stack }}
outputs:
image: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout source code
uses: actions/checkout@master
with:
ref: ${{ env.BRANCH_REF }}
- name: Log in to the Container registry
uses: docker/login-action@master
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ env.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@master
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha
- name: Build and push
uses: docker/build-push-action@master
with:
context: .
build-args: |
NODE_ENV=production
TZ=utc
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
deploy:
needs: [build]
runs-on: saeon
env:
BRANCH_REF: ${{ inputs.stack }}
DEPLOY_SOURCE: deploy/${{ inputs.stack }}/stack.yml
STACK_COMPOSE_PATH: /home/runner/proxy/deploy/${{ inputs.stack }}/stack.yml
STACK_CONFIG_PATH: /home/runner/proxy/deploy/${{ inputs.stack }}/stack.env
steps:
- name: Check out source code
uses: actions/checkout@master
with:
ref: ${{ env.BRANCH_REF }}
- name: (SCP) Copy stack configuration to app server
uses: appleboy/scp-action@master
with:
host: ${{ env.SWARM_HOSTNAME }}
username: ${{ env.SWARM_USERNAME }}
password: ${{ env.SWARM_PASSWORD }}
port: ${{ env.SWARM_SSH_PORT }}
source: ${{ env.DEPLOY_SOURCE }}
target: 'proxy'
- name: (SSH) Deploy stack
uses: appleboy/ssh-action@master
with:
host: ${{ env.SWARM_HOSTNAME }}
username: ${{ env.SWARM_USERNAME }}
password: ${{ env.SWARM_PASSWORD }}
port: ${{ env.SWARM_SSH_PORT }}
script: |
echo "DOCKER_IMAGE=${{ needs.build.outputs.image }}" > ${{ env.STACK_CONFIG_PATH }}
echo "ELASTICSEARCH_NEXT_ADDRESS=${{ env.ELASTICSEARCH_NEXT_ADDRESS }}" >> ${{ env.STACK_CONFIG_PATH }}
echo "ELASTICSEARCH_7_14_ADDRESS=${{ env.ELASTICSEARCH_7_14_ADDRESS }}" >> ${{ env.STACK_CONFIG_PATH }}
echo "ELASTICSEARCH_8_X_ADDRESS=${{ env.ELASTICSEARCH_8_X_ADDRESS }}" >> ${{ env.STACK_CONFIG_PATH }}
sudo /opt/deploy-docker-stack.sh ${{ env.STACK_COMPOSE_PATH }} ${{ env.STACK_CONFIG_PATH }} proxy_${{ inputs.stack }}