-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (102 loc) · 3.16 KB
/
aws.yaml
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
name: Deploy to Amazon EC2
on:
workflow_dispatch:
push:
branches:
- main
- dev
env:
IMAGE_REPO: stepancons
IMAGE_TAG: ${{ github.sha }}
permissions:
contents: read
jobs:
test:
name: Test all application
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.20.3'
- name: Build
run: go build -v $(go list -f '{{.Dir}}/...' -m | xargs)
- name: Test
run: go test -v $(go list -f '{{.Dir}}/...' -m | xargs)
# Push and deploy dev
push-dev:
needs: test
name: Push Dev to DockerHub
runs-on: ubuntu-latest
environment: dev
if: github.event.ref == 'refs/heads/dev' || github.event.ref == 'refs/heads/main'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build, tag, and push image to Docker Hub
id: build-image
env:
IMAGE_REPO: ${{ env.IMAGE_REPO }}
IMAGE_TAG: dev
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
run: |
chmod +x ./scripts/push-to-dockerhub.sh && ./scripts/push-to-dockerhub.sh
deploy-dev:
needs: push-dev
name: Deploy Dev to EC2
runs-on: ubuntu-latest
environment: dev
if: github.event.ref == 'refs/heads/dev' || github.event.ref == 'refs/heads/main'
steps:
- name: Checkout the files
uses: actions/checkout@v3
- name: Copy code to server and run dev
env:
BRANCH: ${{ github.ref_name }}
ENVIRONMENT: dev
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
REMOTE_USER: ${{ secrets.REMOTE_USER }}
TARGET: ${{ secrets.TARGET }}
run: |
echo "$SSH_PRIVATE_KEY" > private_key && chmod 600 private_key
chmod +x ./scripts/deploy.sh && ./scripts/deploy.sh
# Push and deploy prod
push-prod:
needs: deploy-dev
name: Push Prod to DockerHub
runs-on: ubuntu-latest
environment: dev
if: github.event.ref == 'refs/heads/main'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build, tag, and push image to Docker Hub
id: build-image
env:
IMAGE_REPO: ${{ env.IMAGE_REPO }}
IMAGE_TAG: prod
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
run: |
chmod +x ./scripts/push-to-dockerhub.sh && ./scripts/push-to-dockerhub.sh
deploy-prod:
needs: push-prod
name: Deploy Prod to EC2
runs-on: ubuntu-latest
environment: dev
if: github.event.ref == 'refs/heads/main'
steps:
- name: Checkout the files
uses: actions/checkout@v3
- name: Copy code to server and run prod
env:
BRANCH: ${{ github.ref_name }}
ENVIRONMENT: prod
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
REMOTE_USER: ${{ secrets.REMOTE_USER }}
TARGET: ${{ secrets.TARGET }}
run: |
echo "$SSH_PRIVATE_KEY" > private_key && chmod 600 private_key
chmod +x ./scripts/deploy.sh && ./scripts/deploy.sh