-
Notifications
You must be signed in to change notification settings - Fork 1
134 lines (121 loc) · 4.41 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Deploy
on:
push:
branches:
- main
paths:
- 'env.yml'
pull_request: #TODO: remove this line after testing
jobs:
setup-deployment-env:
name: Setup Deployment Environment
runs-on: ubuntu-latest
outputs:
deployment-environments: ${{ steps.get-deployment-environment.outputs.deployment-environments }}
steps:
- name: Checkout config
uses: actions/checkout@v4
- name: Get environments
id: get-deployment-environment
run: echo "deployment-environments=$(jq --compact-output '.environments' ./config/deployment-environment.json)" >> $GITHUB_OUTPUT
# TODO: Get proper versioning
version:
name: Set release version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Set version
id: version
run: echo "version=test1.0" >> $GITHUB_OUTPUT
pack:
name: Pack access-ram-env
runs-on: ubuntu-latest
outputs:
name: ${{ steps.access-ram.outputs.name }}
steps:
- uses: actions/checkout@v4
- name: Get name
id: access-ram
run: echo "name=$(yq '.name' < env.yml)" >> $GITHUB_OUTPUT
- name: Setup Micromamba
uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822 #v1.9.0
with:
micromamba-version: '1.5.8-0'
environment-file: env.yml
environment-name: ${{ steps.access-ram.outputs.name }}
generate-run-shell: true
- name: Create Pack and Lockfile
shell: micromamba-shell {0}
run: |
conda pack
conda-lock lock --file env.yml --platform linux-64 --micromamba --lockfile ${{ steps.access-ram.outputs.name }}.conda-lock.yml
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.access-ram.outputs.name }}
if-no-files-found: error
path: |
${{ steps.access-ram.outputs.name }}.tar.gz
${{ steps.access-ram.outputs.name }}.conda-lock.yml
deploy:
runs-on: ubuntu-latest
needs:
- version
- pack
- setup-deployment-env
strategy:
fail-fast: false
matrix:
deployment-environment: ${{ fromJson(needs.setup-deployment-env.outputs.deployment-environments) }}
environment: ${{ matrix.deployment-environment }}
env:
NAME: ${{ needs.pack.outputs.name }}
VERSION: ${{ needs.version.outputs.version }}
DEPLOYMENT_LOCATION: ${{ vars.DEPLOYMENT_DIR }}/conda/${{ needs.pack.outputs.name }}-${{ needs.version.outputs.version }}
permissions:
contents: write
steps:
- uses: actions/download-artifact@v4
with:
name: ${{ env.NAME }}
- name: Set up SSH
uses: access-nri/actions/.github/actions/setup-ssh@main
id: ssh
with:
hosts: |
${{ secrets.HOST_DATA }}
${{ secrets.HOST }}
private-key: ${{ secrets.SSH_KEY }}
- name: Copy to ${{ matrix.deployment-environment }}
run: |
rsync -e 'ssh -i ${{ steps.ssh.outputs.private-key-path }}' \
${{ env.NAME }}.tar.gz \
${{ secrets.USER }}@${{ secrets.HOST_DATA }}:${{ env.DEPLOYMENT_LOCATION }}
- name: Deploy to ${{ matrix.deployment-environment }}
env:
ENVIRONMENT_LOCATION: ${{ vars.DEPLOYMENT_LOCATION }}
run: |
ssh ${{ secrets.USER }}@${{ secrets.HOST }} -i ${{ steps.ssh.outputs.private-key-path }} /bin/bash <<'EOT'
mkdir -p ${{ env.ENVIRONMENT_LOCATION }}
if [ $? -ne 0 ]; then
exit $?
fi
tar -xzf ${{ vars.DEPLOYMENT_LOCATION }}/${{ env.NAME }}.tar.gz -C ${{ env.ENVIRONMENT_LOCATION }}
source ${{ env.ENVIRONMENT_LOCATION }}/bin/activate
conda-unpack
source ${{ env.ENVIRONMENT_LOCATION }}/bin/deactivate
rm -r ${{ vars.DEPLOYMENT_LOCATION }}/${{ env.NAME }}.tar.gz
# ln -s ${{ vars.MODULE_LOCATION }}/.common ${{ vars.MODULE_LOCATION }}/${{ env.VERSION }}
EOT
# Release
# - name: Create Release
# uses: softprops/[email protected]
# with:
# tag_name: ${{ env.VERSION }}
# name: Payu ${{ env.VERSION }}
# generate_release_notes: true
# fail_on_unmatched_files: true
# files: |
# ./${{ env.NAME }}.tar.gz
# ./${{ env.NAME }}.conda-lock.yml