Merge pull request #16 from vurak/feature/menu-options-as-links #10
Workflow file for this run
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 Image, Push to DockerHub, and Deploy on Server | |
on: | |
# pull_request: | |
# types: [opened, edited] | |
push: | |
tags: | |
- "v[0-9]+.[0-9]+.[0-9]+" | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
inputs: | |
version: | |
description: "Image version" | |
required: true | |
env: | |
IMAGE_NAME: "futile" | |
jobs: | |
build_and_push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and Push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build_and_push | |
steps: | |
- name: SSH to Droplet and Update Container | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SERVER_IP }} | |
username: root | |
key: ${{ secrets.SERVER_SSH_KEY }} | |
passphrase: ${{ secrets.SERVER_SSH_PASSPHRASE }} | |
envs: IMAGE_NAME | |
# TODO: run a docker-compose.yml file in /home/surak/futile instead | |
# have that file do what is happening below but also create the database | |
script: | | |
# Login to registry | |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }} | |
# Stop running container | |
docker stop $(echo $IMAGE_NAME) | |
# Remove old container | |
docker rm $(echo $IMAGE_NAME) | |
# Pull latest image | |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/$(echo $IMAGE_NAME):latest | |
# Run a new container from the new image | |
echo ${{ secrets.DOCKERHUB_USERNAME }}/$(echo $IMAGE_NAME):latest | |
docker compose -f /home/surak/futile.me/docker-compose.yml up -d | |
# docker run -d \ | |
# --restart always \ | |
# --name $(echo $IMAGE_NAME) \ | |
# -p 3000:3000 \ | |
# ${{ secrets.DOCKERHUB_USERNAME }}/$(echo $IMAGE_NAME):latest |