-
Notifications
You must be signed in to change notification settings - Fork 0
60 lines (51 loc) · 1.62 KB
/
deploy.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
name: Deployment Dev
on:
push:
branches:
- main
workflow_dispatch:
inputs:
env_file:
description: 'Environment file to use (e.g., .env, .env_prod)'
required: true
default: '.env'
jobs:
build-and-deploy:
name: Build and Deployment
runs-on: ubuntu-20.04
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Docker Image
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
push: true
tags: ghcr.io/${{ github.actor }}/launchpad:main
build-args:
ENV_FILE=${{ github.event.inputs.env_file }}
# Deploy to Server
- name: SSH & Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_SERVER_IP }}
username: ${{ secrets.SSH_SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
# Stop and remove existing containers
docker-compose -f docker-compose.yml down
# Remove dangling images
docker rmi $(docker images -f "dangling=true" -q)
# Pull and run the new image
docker-compose -f docker-compose.yml pull
GITHUB_USERNAME=${{ github.actor }} docker-compose up -d --build
exit 0;