-
Notifications
You must be signed in to change notification settings - Fork 7
101 lines (91 loc) · 3.45 KB
/
build-and-publish.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
97
98
99
100
101
name: Build and Publish
on:
push:
paths-ignore:
- 'tests/**'
branches: [main]
pull_request:
paths-ignore:
- 'tests/**'
jobs:
build-and-push-docker-image:
name: Build Docker image and push to repositories
runs-on: ubuntu-latest
outputs:
sha_version: ${{ steps.vars.outputs.sha_short }}
commit_msg: ${{ steps.vars.outputs.commit_msg }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set outputs
id: vars
run: |
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
echo "::set-output name=commit_msg::$(git log -1 --pretty=format:\"%s\")"
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
if: github.ref == 'refs/heads/main'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Generate container version
id: docker_build_version
env:
GITHUB_RUN_NUMBER: ${{ github.run_number }}
run: echo "::set-output name=version::$(date +'%Y-%m-%d').$GITHUB_RUN_NUMBER"
- name: Build container image and push to Docker Hub
uses: docker/build-push-action@v4
with:
context: .
load: false
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/pathology:latest
${{ secrets.DOCKERHUB_USERNAME }}/pathology:${{ steps.vars.outputs.sha_short }}
${{ secrets.DOCKERHUB_USERNAME }}/pathology:${{ steps.docker_build_version.outputs.version }}
${{ secrets.DOCKERHUB_USERNAME }}/pathology-socket:latest
${{ secrets.DOCKERHUB_USERNAME }}/pathology-socket:${{ steps.vars.outputs.sha_short }}
${{ secrets.DOCKERHUB_USERNAME }}/pathology-socket:${{ steps.docker_build_version.outputs.version }}
push: ${{ github.ref == 'refs/heads/main' }}
config:
name: Config
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
outputs:
get-server-ip-list: ${{ steps.get-server-ip-list.outputs.get-server-ip-list }}
steps:
- id: get-server-ip-list
name: Get Server IP List
run: echo "get-server-ip-list=$(dig +short app-servers.pathology.gg TXT | jq -cr 'split(",")')" >> $GITHUB_OUTPUT
- name: print output
run: |
echo "${{ steps.get-server-ip-list.outputs.get-server-ip-list }}"
deploy-to-staging:
name: Deploy to Staging
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: [build-and-push-docker-image, config]
strategy:
matrix:
server: ${{ fromJson(needs.config.outputs.get-server-ip-list) }}
steps:
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/pathology
chmod 600 ~/.ssh/pathology
cat >>~/.ssh/config <<END
Host *
User $SSH_USER
IdentityFile ~/.ssh/pathology
StrictHostKeyChecking no
END
env:
SSH_USER: ${{ secrets.SERVER_SSH_USER }}
SSH_KEY: ${{ secrets.SERVER_SSH_KEY }}
- name: Update Environments with New Containers
run: ssh ${{ matrix.server }} 'bash /opt/pathology/scripts/update-Environments.sh -e stage -v ${{ needs.build-and-push-docker-image.outputs.sha_version }}'