Staging-1 π #10
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: 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 |