forked from GMOD/Apollo3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47a61db
commit 881c1fc
Showing
2 changed files
with
108 additions
and
61 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
name: Deploy | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
environment: | ||
required: true | ||
type: string | ||
secrets: | ||
aws_access_key_id: | ||
required: true | ||
aws_secret_access_key: | ||
required: true | ||
ssh_private_key: | ||
required: true | ||
jwt_secret: | ||
required: true | ||
session_secret: | ||
required: true | ||
google_client_id: | ||
required: true | ||
google_client_secret: | ||
required: true | ||
github_token: | ||
required: true | ||
|
||
jobs: | ||
deploy: | ||
name: Deploy to demo staging server | ||
runs-on: ubuntu-latest | ||
environment: ${{ inputs.environment }} | ||
needs: build-and-push-docker | ||
steps: | ||
- name: Check out | ||
uses: actions/checkout@v3 | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v2 | ||
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 }} | ||
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 |
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