Skip to content

Commit af28638

Browse files
add workflow to deploy
1 parent e186b78 commit af28638

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed

.github/workflows/deploy.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Elixir CI/CD
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
name: Run Tests
11+
services:
12+
db:
13+
image: postgres:14
14+
env:
15+
POSTGRES_USER: postgres
16+
POSTGRES_PASSWORD: postgres
17+
POSTGRES_DB: postgres
18+
ports: ['5432:5432']
19+
options: >-
20+
--health-cmd pg_isready
21+
--health-interval 10s
22+
--health-timeout 5s
23+
--health-retries 5
24+
steps:
25+
- uses: actions/checkout@v2
26+
- uses: actions/[email protected]
27+
with:
28+
elixir-version: 1.14.2
29+
otp-version: 24.1
30+
- name: Cache dependencies
31+
uses: actions/cache@v2
32+
with:
33+
path: deps
34+
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
35+
restore-keys: |
36+
${{ runner.os }}-mix-
37+
- name: Install Dependencies
38+
run: mix deps.get
39+
- name: Start Hasura GraphQL Engine
40+
env:
41+
HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
42+
HASURA_GRAPHQL_ENABLE_CONSOLE: "false"
43+
HASURA_GRAPHQL_DEV_MODE: "true"
44+
HASURA_GRAPHQL_ADMIN_SECRET: helloworld
45+
HASURA_GRAPHQL_UNAUTHORIZED_ROLE: visitor
46+
HASURA_GRAPHQL_STRINGIFY_NUMERIC_TYPES: "true"
47+
run: |
48+
docker run -d --name graphql-engine --network host \
49+
-e HASURA_GRAPHQL_METADATA_DATABASE_URL=${{ env.HASURA_GRAPHQL_METADATA_DATABASE_URL }} \
50+
-e HASURA_GRAPHQL_ENABLE_CONSOLE=${{ env.HASURA_GRAPHQL_ENABLE_CONSOLE }} \
51+
-e HASURA_GRAPHQL_DEV_MODE=${{ env.HASURA_GRAPHQL_DEV_MODE }} \
52+
-e HASURA_GRAPHQL_ADMIN_SECRET=${{ env.HASURA_GRAPHQL_ADMIN_SECRET }} \
53+
-e HASURA_GRAPHQL_UNAUTHORIZED_ROLE=${{ env.HASURA_GRAPHQL_UNAUTHORIZED_ROLE }} \
54+
-e HASURA_GRAPHQL_STRINGIFY_NUMERIC_TYPES=${{ env.HASURA_GRAPHQL_STRINGIFY_NUMERIC_TYPES }} \
55+
hasura/graphql-engine:v2.40.0
56+
- name: Run Tests
57+
run: mix test
58+
59+
build:
60+
runs-on: ubuntu-latest
61+
needs: test
62+
steps:
63+
- uses: actions/checkout@v2
64+
- name: Set up Docker Buildx
65+
uses: docker/setup-buildx-action@v1
66+
- name: Log in to GitHub Container Registry
67+
uses: docker/login-action@v1
68+
with:
69+
registry: ghcr.io
70+
username: ${{ github.actor }}
71+
password: ${{ secrets.GITHUB_TOKEN }}
72+
- name: Build and Push Docker Image
73+
uses: docker/build-push-action@v2
74+
with:
75+
context: .
76+
push: true
77+
tags: ghcr.io/${{ github.repository_owner }}/my_phoenix_app:${{ github.sha }}
78+
79+
deploy:
80+
runs-on: ubuntu-latest
81+
needs: build
82+
steps:
83+
- name: Deploy to Digital Ocean
84+
uses: appleboy/ssh-action@master
85+
with:
86+
host: ${{ secrets.DIGITAL_OCEAN_HOST }}
87+
username: ${{ secrets.DIGITAL_OCEAN_USERNAME }}
88+
key: ${{ secrets.DIGITAL_OCEAN_SSH_KEY }}
89+
script: |
90+
docker pull ghcr.io/${{ github.repository_owner }}/my_phoenix_app:${{ github.sha }}
91+
docker stop my_phoenix_app || true
92+
docker rm my_phoenix_app || true
93+
docker run -d --name my_phoenix_app -p 80:4000 ghcr.io/${{ github.repository_owner }}/my_phoenix_app:${{ github.sha }}

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,7 @@ npm-debug.log
3636
/assets/node_modules/
3737

3838
# Db hasura setup
39-
/db/node_modules
39+
/db/node_modules/
40+
41+
# SSH keys
42+
.ssh/

0 commit comments

Comments
 (0)