Skip to content

Commit

Permalink
Fix github action
Browse files Browse the repository at this point in the history
  • Loading branch information
邱宇軒Yuh Suan Chiu committed Feb 10, 2024
1 parent 50e7115 commit 43bf889
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
54 changes: 37 additions & 17 deletions .github/workflows/deploy-docker-gce.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,61 @@ on:
- dev # Replace with your branch

jobs:
build:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Build and push Docker image
uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Check for changes
id: changes
uses: dorny/paths-filter@v3
with:
filters: |
src:
- 'src/**'
- 'Dockerfile'
- name: Login to DockerHub
uses: docker/login-action@v3
with:
context: .
file: ./Dockerfile
push: true
tags: arcade0425/snap_up_thsr:latest
username: arcade0425
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
if: steps.changes.outputs.matched == 'true'

- name: Build and push Docker image
run: |
docker build -t arcade0425/snap_up_thsr:latest .
docker push arcade0425/snap_up_thsr:latest
if: steps.changes.outputs.matched == 'true'

deploy:
needs: build
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Setup Google Cloud SDK
uses: google-github-actions/setup-gcloud@v1
# - run: |
# echo 123 && echo ${{ vars.INSTANCE_REGION }}
- uses: 'actions/checkout@v4'

- name: Google Cloud Auth
uses: google-github-actions/auth@v2
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true
credentials_json: ${{ secrets.GCP_CREDENTIALS }}

- name: Deploy to GCE
run: |
gcloud compute ssh ${{ secrets.GCP_USER }}@${{ secrets.GCP_INSTANCE }} --zone=${{ variables.INSTANCE_REGION }} -- "cd snap_up_thsr && \
docker pull arcade0425/snap_up_thsr:latest && \
docker run --network=${{ secrets.LIVE_NETWORK }} \
gcloud compute ssh ${{ secrets.GCP_USER }}@${{ secrets.GCP_INSTANCE }} --zone=${{ vars.INSTANCE_REGION }} -- "sudo docker pull arcade0425/snap_up_thsr:latest && \
sudo docker stop snap_up_thsr && \
sudo docker rm snap_up_thsr && \
sudo docker run --network=${{ secrets.LIVE_NETWORK }} \
-p 8080:8000 \
-e REDIS_HOST=${{ secrets.REDIS_HOST }} \
-e DB_HOST=${{ secrets.DB_HOST }} \
-e DB_USER=${{ secrets.DB_USER }} \
-e DB_PASSWORD=${{ secrets.DB_PASSWORD }} \
-e DB_NAME=${{ secrets.DB_NAME }} \
-e deploy=live \
-e DEPLOY=live \
-d \
--restart=always \
--name snap_up_thsr \
arcade0425/snap_up_thsr:latest
arcade0425/snap_up_thsr:latest"
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ COPY ./src .

ADD requirements /requirements

RUN mkdir -p logs/

RUN apt update && \
apt install -y libpq5 procps && \
pip install -r /requirements/live.txt
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ COPY ./src .

ADD requirements/local.txt /tmp/

RUN mkdir -p logs/

RUN apt update && \
apt install -y libpq5 procps && \
pip install -r /tmp/local.txt && \
Expand Down

0 comments on commit 43bf889

Please sign in to comment.