Deploy to demo server #41
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to demo server | |
on: | |
workflow_call: | |
inputs: | |
environment: | |
required: true | |
type: string | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: Environment to deploy | |
type: environment | |
required: true | |
jobs: | |
build: | |
name: Build and upload | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out | |
uses: actions/checkout@v4 | |
- name: Use Node.js 18.x | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18 | |
cache: yarn | |
- name: Install | |
run: yarn --immutable | |
- name: Build plugin | |
run: yarn build | |
working-directory: packages/jbrowse-plugin-apollo | |
- name: Upload built plugin files | |
uses: actions/upload-artifact@v4 | |
with: | |
name: plugin | |
path: | | |
packages/jbrowse-plugin-apollo/dist/jbrowse-plugin-apollo.umd.development.js | |
packages/jbrowse-plugin-apollo/dist/jbrowse-plugin-apollo.umd.production.min.js | |
deploy: | |
name: Deploy to ${{ inputs.environment }} demo server | |
runs-on: ubuntu-latest | |
environment: ${{ inputs.environment }} | |
needs: [build] | |
steps: | |
- name: Check out | |
uses: actions/checkout@v4 | |
- name: Download built plugin files | |
uses: actions/download-artifact@v4 | |
with: | |
name: plugin | |
path: .github/workflows/deploy/ | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-east-1 | |
- name: Get instance address | |
id: ec2-describe-instances | |
run: | | |
INSTANCE_ADDRESS=$(aws ec2 describe-instances \ | |
--instance-ids ${{ vars.INSTANCE_ID }} \ | |
--query "Reservations[*].Instances[*].[PublicDnsName]" \ | |
--output text) | |
echo "INSTANCE_ADDRESS=$INSTANCE_ADDRESS" >> "$GITHUB_OUTPUT" | |
- name: Set up SSH | |
run: | | |
mkdir --parents ~/.ssh | |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/staging | |
chmod 600 ~/.ssh/staging | |
cat >>~/.ssh/config <<END | |
Host staging | |
HostName ${{ steps.ec2-describe-instances.outputs.INSTANCE_ADDRESS }} | |
User ec2-user | |
IdentityFile ~/.ssh/staging | |
END | |
ssh-keyscan -H ${{ steps.ec2-describe-instances.outputs.INSTANCE_ADDRESS }} >> ~/.ssh/known_hosts | |
- name: Create Docker context | |
run: | | |
docker context create staging \ | |
--docker host=ssh://staging \ | |
--description "Staging server" | |
- name: Log in to the GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Deploy | |
env: | |
JWT_SECRET: ${{ secrets.JWT_SECRET }} | |
SESSION_SECRET: ${{ secrets.SESSION_SECRET }} | |
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} | |
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} | |
ROOT_USER_NAME: ${{ secrets.ROOT_USER_NAME }} | |
ROOT_USER_PASSWORD: ${{ secrets.ROOT_USER_PASSWORD }} | |
URL: ${{ vars.URL }} | |
working-directory: .github/workflows/deploy | |
run: | | |
docker --context staging compose down | |
docker --context staging compose pull | |
docker --context staging compose up --build --detach |