Skip to content

Commit

Permalink
fix: github actions bug with env
Browse files Browse the repository at this point in the history
  • Loading branch information
svifty7 committed Oct 11, 2024
1 parent a78c631 commit a83502c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,27 @@ on:

env:
ENVIRONMENT_NAME: ${{github.ref_name == 'main' && 'prod' || 'dev'}}
CONTAINER_NAME: ttg-next-api-${{env.ENVIRONMENT_NAME}}
IMAGE_NAME: ${{secrets.DOCKER_HUB_USERNAME}}/${{env.CONTAINER_NAME}}
NETWORK_NAME: ttg-next-network-${{env.ENVIRONMENT_NAME}}

concurrency:
group: deploy-${{github.ref_name}}
cancel-in-progress: false

jobs:
env:
name: Update env
runs-on: ubuntu-latest
env:
CONTAINER_NAME: ttg-next-api-${{github.ref_name == 'main' && 'prod' || 'dev'}}
outputs:
CONTAINER_NAME: ${{env.CONTAINER_NAME}}
NETWORK_NAME: ttg-next-network-${{env.ENVIRONMENT_NAME}}
IMAGE_NAME: ${{secrets.DOCKER_HUB_USERNAME}}/${{env.CONTAINER_NAME}}:latest
steps:
- run: echo "env is updated"

build:
name: Build to Docker Hub
needs: env
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -35,7 +45,7 @@ jobs:
- name: Maven Install
run: mvn -B clean install

- uses: docker/login-action@v2
- uses: docker/login-action@v3
with:
username: ${{secrets.DOCKER_HUB_USERNAME}}
password: ${{secrets.DOCKER_HUB_TOKEN}}
Expand All @@ -45,11 +55,11 @@ jobs:
context: .
file: ./Dockerfile
push: true
tags: ${{env.IMAGE_NAME}}
tags: ${{needs.env.outputs.IMAGE_NAME}}

ssh:
name: Update Server
needs: build
needs: [env, build]
runs-on: ubuntu-latest
steps:
- uses: appleboy/ssh-action@master
Expand All @@ -59,17 +69,17 @@ jobs:
key: ${{secrets.TMWEB_SSH_KEY}}
port: ${{secrets.TMWEB_SSH_PORT}}
script: |
docker stop ${{env.CONTAINER_NAME}} && docker rm ${{env.CONTAINER_NAME}}
docker pull ${{env.IMAGE_NAME}}
docker stop ${{needs.env.outputs.CONTAINER_NAME}} && docker rm ${{needs.env.outputs.CONTAINER_NAME}}
docker pull ${{needs.env.outputs.IMAGE_NAME}}
docker run \
--network ${{env.NETWORK_NAME}} \
--network ${{needs.env.outputs.NETWORK_NAME}} \
--ip ${{secrets.DOCKER_API_CONTAINER_IP}} \
--name ${{env.CONTAINER_NAME}} \
--name ${{needs.env.outputs.CONTAINER_NAME}} \
-d \
-e spring.profiles.active=${{env.ENVIRONMENT_NAME}} \
-e dbhost=${{secrets.DOCKER_MYSQL_IP}} \
-e dbuser=${{secrets.DOCKER_MYSQL_USER}} \
-e dbpassword=${{secrets.DOCKER_MYSQL_PASSWORD}} \
-e emailpassword=${{secrets.EMAIL_PASSWORD}} \
${{env.IMAGE_NAME}}
${{needs.env.outputs.IMAGE_NAME}}
docker rmi $(docker images --filter "dangling=true" -q --no-trunc) &
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand Down

0 comments on commit a83502c

Please sign in to comment.