Skip to content

Commit

Permalink
First deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
albertolerda committed Oct 3, 2022
1 parent 9f45293 commit 57e9826
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export HERE_API=YOUR API KEY
export PORT=8080
15 changes: 15 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
on:
release:
types: [created]

jobs:
release-linux-amd64:
name: release linux/amd64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: wangyoucao577/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: linux
goarch: amd64
9 changes: 9 additions & 0 deletions devops/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ANSIPLAY = ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook --inventory hosts.toml --ssh-common-args '-o StrictHostKeyChecking=accept-new -o IdentitiesOnly=yes' --private-key ./sshkey $(1)

##@ General
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' Makefile

##@ Server management
install: ## Install controller
$(call ANSIPLAY, install-proxy.yml)
1 change: 1 addition & 0 deletions devops/hosts.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
116.203.117.144 ansible_port=22010
54 changes: 54 additions & 0 deletions devops/install-proxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
- name: Create non root user
hosts: all
remote_user: root
tasks:
- name: Add the user 'proxy'
ansible.builtin.user:
name: proxy
shell: /bin/bash
- name: Create .ssh directory
file:
path: /home/proxy/.ssh
state: directory
owner: proxy
group: proxy
- name: Set authorized keys for user controller
copy:
src: /root/.ssh/authorized_keys
remote_src: true
dest: /home/controller/.ssh/authorized_keys
owner: controller
group: controller
- name: Install zenflows proxy
hosts: all
remote_user: root
become_user: proxy
become_method: su
tasks:
- name: Install package dependencies
ansible.builtin.package:
name:
- nginx
- tmux
state: latest
- name: Build app
command: make
args:
chdir: ..
delegate_to: localhost
- name: copy executable
copy:
dest: "/zf-proxy"
src: "../zf-proxy"
owner: proxy
group: proxy
- name: copy executable
copy:
dest: "/.env"
src: "../.env.production"
owner: proxy
group: proxy
- name: run proxy
# become: true
command: tmux new-session -d -s zenflows-proxy "source /.env && /zf-proxy"
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ func main() {
for i := 0; i<len(proxiedHosts); i++{
http.HandleFunc(proxiedHosts[i].addHandle())
}
err := http.ListenAndServe(":8080", nil)

portStr := fmt.Sprintf(":%s", os.Getenv("PORT"))

fmt.Printf("Starting server on port %s\n", os.Getenv("PORT"))
err := http.ListenAndServe(portStr, nil)
if errors.Is(err, http.ErrServerClosed) {
fmt.Printf("server closed\n")
} else if err != nil {
Expand Down

0 comments on commit 57e9826

Please sign in to comment.