Skip to content

Staging-1 πŸ—

Staging-1 πŸ— #10

Workflow file for this run

name: Staging-1 πŸ—
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 code πŸ”Ž
uses: actions/checkout@v3
- name: Build Docker image 🐳
run: |
docker build \
-f docker/Dockerfile \
-t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_STAGE_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_STAGE_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_STAGE_IMAGE_NAME }};
docker stop ${{ secrets.DOCKER_STAGE_IMAGE_NAME }} || true;
docker rm ${{ secrets.DOCKER_STAGE_IMAGE_NAME }} || true;
docker rm -f $(docker ps -a -q)
docker rmi -f $(docker images -q)
docker run -e PORT=8082 -d -env-file=/home/ubuntu/staging.env --name ${{ secrets.DOCKER_STAGE_IMAGE_NAME }} -p 8082:8082 ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_STAGE_IMAGE_NAME }};
exit
"
- name: Cleanup 🧹
run: rm -rf ~/.ssh