Update Dockerfile #12
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: Build and Deploy | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check Out Repo | |
uses: actions/checkout@v2 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_ACCESS_KEY }} | |
- name: Build and Push Docker image | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: easc01/sway-server:latest | |
- name: Verify Pushed Image | |
run: docker pull easc01/sway-server:latest | |
- name: Deploy to EC2 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
key: ${{ secrets.SSH_KEY }} | |
script: | | |
sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_ACCESS_KEY }} | |
sudo docker pull easc01/sway-server:latest | |
sudo docker stop sway-server || true | |
sudo docker rm sway-server || true | |
sudo docker run -d \ | |
--name sway-server \ | |
--restart=unless-stopped \ | |
-p ${{ vars.SERVER_PORT }}:${{ vars.SERVER_PORT }} \ | |
-e SERVER_PORT=${{ vars.SERVER_PORT }} \ | |
-e JWT_SECRET=${{ secrets.JWT_SECRET }} \ | |
-e IMAGE_CDN_BASE_URL=${{ vars.IMAGE_CDN_BASE_URL }} \ | |
-e DB_HOSTNAME=${{ secrets.DB_HOSTNAME }} \ | |
-e DB_USER=${{ secrets.DB_USER }} \ | |
-e DB_PASSWORD=${{ secrets.DB_PASSWORD }} \ | |
-e DB_DATABASE=${{ secrets.DB_DATABASE }} \ | |
-e YT_KEY=${{ secrets.YT_KEY }} \ | |
-e S3_BUCKET_NAME=${{ secrets.S3_BUCKET_NAME }} \ | |
-e AWS_REGION=${{ secrets.AWS_REGION }} \ | |
-e AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} \ | |
-e AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} \ | |
easc01/sway-server:latest |