Skip to content

Production πŸš€ #103

Production πŸš€

Production πŸš€ #103

Workflow file for this run

name: Production πŸš€
on:
workflow_dispatch:
jobs:
inspection:
name: Run inspection πŸ§ͺ
runs-on: ubuntu-latest
steps:
- name: Use Node.js 21.5.0
uses: actions/setup-node@v3
with:
node-version: '21.5.0'
- name: Checkout repository πŸ”Ž
uses: actions/checkout@v3
- name: Install dependencies πŸ“¦
run: yarn install
- name: Lint code ✍️️
run: yarn lint
- name: Run tests βœ…
run: yarn test
build:
name: Build and publish image πŸ› οΈ
runs-on: ubuntu-latest
steps:
- name: Checkout repository πŸ”Ž
uses: actions/checkout@v3
- name: Build Docker image 🐳
run: |
docker build \
-f docker/app.Dockerfile \
-t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_PROD_IMAGE_NAME }}:latest \
.
- name: Publish Docker image πŸ“¦
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_PROD_IMAGE_NAME }}
deploy:
needs: build
name: Deploy image πŸš€
runs-on: ubuntu-latest
steps:
- name: Create ssh keys πŸ”‘
run: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{ secrets.SSHKEY }}" > ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.HOST }} > ~/.ssh/known_hosts
- name: Pull and run container πŸƒοΈ
run: |
ssh ${{ secrets.USERNAME }}@${{ secrets.HOST }} "
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }};
docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_PROD_IMAGE_NAME }};
docker stop prod-minddaily-frontend || true;
docker rm prod-minddaily-frontend || true;
docker run -e PORT=8081 -d --name prod-minddaily-frontend -p 8081:8081 ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_PROD_IMAGE_NAME }};
exit
"
- name: Cleanup 🧹
run: rm -rf ~/.ssh