-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (108 loc) · 4.17 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
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
118
119
120
121
122
123
124
125
126
127
128
129
name: CI/CD Development Env
on:
push:
branches: ["main"]
# pull_request:
# branches: ["main"]
env:
REGISTRY: ghcr.io
REGISTRY_USERNAME: ${{ github.actor }}
REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
IMAGE_NAME: ${{ github.repository }}
WORKER_IMAGE_NAME: ${{ github.repository }}-worker
jobs:
test-build-dev:
name: Test & Build for Development env
# if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ["socious-v3-dev"]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Go environment
uses: actions/[email protected]
with:
go-version: '1.22.5'
- name: Copying build & test environment
run: |
cp /etc/socious-api-v3/config.yml .
cp /etc/socious-api-v3/test.config.yml .
- name: Downloading dependencies
run: |
go mod download
- name: Running tests
run: |
go test -v ./tests
- name: Run DB migrations
run: |
go run cmd/migrate/main.go up
- name: Docker Setup Buildx
uses: docker/[email protected]
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.REGISTRY_USERNAME }}
password: ${{ env.REGISTRY_PASSWORD }}
- name: Extract Docker metadata
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
id: build-and-push
uses: docker/[email protected]
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# - name: Extract Worker Docker metadata
# id: meta-worker
# uses: docker/[email protected]
# with:
# images: ${{ env.REGISTRY }}/${{ env.WORKER_IMAGE_NAME }}
# - name: Build and push Worker Docker image
# id: build-and-push-worker
# uses: docker/[email protected]
# with:
# context: .
# file: "./Worker.Dockerfile"
# push: ${{ github.event_name != 'pull_request' }}
# tags: ${{ steps.meta-worker.outputs.tags }}
# labels: ${{ steps.meta-worker.outputs.labels }}
deploy-dev:
needs: [test-build-dev]
name: Deploy to Dev
# if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ["socious-v3-dev"]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Docker run
run: |
docker pull ${{ steps.meta.outputs.tags }}
docker ps -qa --filter "name=socious-api-v3" | grep -q . && docker stop socious-api-v3 && docker rm -fv socious-api-v3
docker run -d --restart always -p 5063:5063 -h socious-api-v3 --network sociousapiv3_default --name socious-api-v3 ${{ steps.meta.outputs.tags }}
# - name: Extract Docker metadata
# id: meta-worker
# uses: docker/[email protected]
# with:
# images: ${{ env.REGISTRY }}/${{ env.WORKER_IMAGE_NAME }}
# - name: Docker run worker
# run: |
# docker pull ${{ steps.meta-worker.outputs.tags }}
# docker ps -qa --filter "name=socious-api-v3-worker" | grep -q . && docker stop socious-api-v3-worker && docker rm -fv socious-api-v3-worker
# docker run -d --restart always -h socious-api-v3-worker --network sociousapiv3_default --name socious-api-v3-worker ${{ steps.meta-worker.outputs.tags }}