Skip to content

Updated 'deploy.yml' for testing. #36

Updated 'deploy.yml' for testing.

Updated 'deploy.yml' for testing. #36

Workflow file for this run

name: Deploy
on:
push:
branches:
- main
paths:
- 'env.yml'
pull_request: #FIXME: Remove 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: Change from VERSION file to something more robust in future
version:
name: Set release version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Set version
id: version
# cat the version file and remove newlines, just in case
run: echo "version=$(cat VERSION | tr -d '\n')" >> $GITHUB_OUTPUT
pack:
name: Pack access-ram-env
runs-on: ubuntu-latest
needs: version
env:
VERSION: ${{ needs.version.outputs.version }}
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 }}-${{env.VERSION}}
generate-run-shell: true
- name: Create Pack and Lockfile
shell: micromamba-shell {0}
run: |
conda pack -o ${{ steps.access-ram.outputs.name }}-${{env.VERSION}}.tar.gz
conda-lock lock --file env.yml --platform linux-64 --micromamba --lockfile ${{ steps.access-ram.outputs.name }}-${{env.VERSION}}.conda-lock.yml
- name: Upload Artifact
env:
PACKAGE_NAME: ${{ steps.access-ram.outputs.name }}-${{ env.VERSION }}
uses: actions/upload-artifact@v4
with:
name: ${{ env.PACKAGE_NAME }}
if-no-files-found: error
path: |
${{ env.PACKAGE_NAME }}.tar.gz
${{ env.PACKAGE_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:
VERSION: ${{ needs.version.outputs.version }}
PACKAGE_NAME: ${{ needs.pack.outputs.name }}-${{ needs.version.outputs.version }}
permissions:
contents: write
steps:
- uses: actions/download-artifact@v4
with:
name: ${{ env.PACKAGE_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 -v -e 'ssh -i ${{ steps.ssh.outputs.private-key-path }}' \
${{ env.PACKAGE_NAME }}.tar.gz \
${{ secrets.USER }}@${{ secrets.HOST_DATA }}:${{ vars.PACK_DIR }}
- name: Deploy to ${{ matrix.deployment-environment }}
env:
DEPLOYMENT_DIR: ${{ vars.ENVIRONMENT_DIR }}/${{ env.VERSION }}
run: |
ssh ${{ secrets.USER }}@${{ secrets.HOST }} -i ${{ steps.ssh.outputs.private-key-path }} /bin/bash <<'EOT'
mkdir -p ${{ env.DEPLOYMENT_DIR }}
tar -xzf ${{ vars.PACK_DIR }}/${{ env.PACKAGE_NAME }}.tar.gz -C ${{ env.DEPLOYMENT_DIR }}
source ${{ env.DEPLOYMENT_DIR }}/bin/activate
conda-unpack
source ${{ env.DEPLOYMENT_DIR }}/bin/deactivate
ln -sf ${{ vars.MODULE_DIR }}/.common ${{ vars.MODULE_DIR }}/${{ env.VERSION }}
EOT
- name: Create Release
uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 #v2.0.8
with:
tag_name: ${{ env.VERSION }}
name: ACCESS-RAM conda environment ${{ env.VERSION }}
generate_release_notes: true
fail_on_unmatched_files: true
files: |
./${{ env.PACKAGE_NAME }}.tar.gz
./${{ env.PACKAGE_NAME }}.conda-lock.yml