Skip to content

Commit

Permalink
CD stage && stop track .env ...
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeMaster482 committed Nov 9, 2023
1 parent 92de501 commit 87a9689
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 29 deletions.
28 changes: 0 additions & 28 deletions .env

This file was deleted.

105 changes: 105 additions & 0 deletions .github/workflows/CD.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: CD

env:
REGISTRY: "codemaster482"
IMAGE_NAME: "HammyWallet-Server"
CONTAINER_NAME: "HammyWallet-API"
FOLDER_COMPOSE: "backend/2023_2_Hamster"

on:
push:
branches:
Expand All @@ -11,3 +17,102 @@ on:
- deploy

jobs:
lint_and_test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21.x'
cache: false

- name: golangci-lint
uses: golangci/golangci-lint-action@v3

- name: Test with the Go CLI
run: go test ./...


push_to_dockerhub:
runs-on: ubuntu-latest
needs: lint_and_test

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Buildx
uses: docker/setup-buildx-action@v2

- name: DockerHub login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set env
run: echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | head -c 8)" >> $GITHUB_ENV

- name: Build docker and push to dockerhub of CodeMaster
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.GITHUB_SHA_SHORT }}, ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
file: ./build/Dockerfile.multistage.main
build-args: |
IMAGE_NAME=${{ env.IMAGE_NAME }}
REGISTRY=${{ env.REGISTRY }}
GITHUB_SHA_SHORT=${{ env.GITHUB_SHA_SHORT }}

remote_deploy:
runs-on: ubuntu-latest
needs: build_and_push

steps:
- name: Deploy docker-compose via SSH action
uses: appleboy/[email protected]
with:
host: ${{ secrets.DEPLOY_HOST }}
port: ${{ secrets.DEPLOY_PORT }}
username: ${{ secrets.DEPLOY_USERNAME }}
key: ${{ secrets.SSHKEY }}
rm: true
source: docker-compose.yaml, build/sql/create.sql # ?????
target: ~/${{ env.FOLDER_COMPOSE }}

- name: Get docker form dockerhub via SSH action
uses: appleboy/[email protected]
with:
host: ${{ secrets.DEPLOY_HOST }}
port: ${{ secrets.DEPLOY_PORT }}
username: ${{ secrets.DEPLOY_USERNAME }}
key: ${{ secrets.SSHKEY }}
envs: REGISTRY, IMAGE_NAME, CONTAINER_NAME, GITHUB_SHA, FOLDER_COMPOSE
script: |
sudo bash
cd $(echo $FOLDER_COMPOSE)
# Make .env variables file
cat <<EOF>.env
POSTGRES_DB=${{ secrets.POSTGRES_DB }}
POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}
DB_HOST=${{ secrets.DB_HOST }}
DB_PORT=${{ secrets.DB_PORT }}
POSTGRES_USER=${{ secrets.POSTGRES_USER }}
PGADMIN_DEFAULT_EMAIL=${{ secrets.PGADMIN_DEFAULT_EMAIL }}
PGADMIN_DEFAULT_PASSWORD=${{ secrets.PGADMIN_DEFAULT_PASSWORD }}
JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}
IMAGE_NAME=${{ env.IMAGE_NAME }}
REGISTRY=${{ env.REGISTRY }}
CONTAINER_NAME=${{ env.CONTAINER_NAME }}
EOF
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ app
*.idea
*.bin
*.tmp
.env
#env

# Logs
logs
Expand Down

0 comments on commit 87a9689

Please sign in to comment.