-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92de501
commit 87a9689
Showing
3 changed files
with
106 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ app | |
*.idea | ||
*.bin | ||
*.tmp | ||
.env | ||
#env | ||
|
||
# Logs | ||
logs | ||
|