-
Notifications
You must be signed in to change notification settings - Fork 16
61 lines (53 loc) · 1.97 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Build
on:
push:
branches: [ "main" ]
jobs:
Deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js 16.13.2
uses: actions/setup-node@v3
with:
node-version: 16.13.2
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/koders-portfolio:latest
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
- name: Cleaning remote docker image and container
uses: fifsky/ssh-action@master
continue-on-error: true
with:
command: |
docker rm $(docker stop $(docker ps -a -q --filter ancestor=${{ secrets.DOCKER_HUB_USERNAME }}/koders-portfolio --format="{{.ID}}")) &&
docker rmi ${{ secrets.DOCKER_HUB_USERNAME }}/koders-portfolio
host: ${{ secrets.HOST }}
user: ${{ secrets.USERNAME }}
pass: ${{ secrets.PASSWORD}}
port: ${{ secrets.PORT}}
- name: Building and deploying new website
uses: fifsky/ssh-action@master
with:
command: |
docker run -d -p 8080:80 --name koders-portfolio ${{ secrets.DOCKER_HUB_USERNAME }}/koders-portfolio
host: ${{ secrets.HOST }}
user: ${{ secrets.USERNAME }}
pass: ${{ secrets.PASSWORD}}
port: ${{ secrets.PORT}}