fix container name #3
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
name: Continuous Integration and Deployment | |
on: | |
pull_request: | |
branches: [master] | |
push: | |
branches: [master] | |
env: | |
GITHUB_COMMIT_ID: ${{github.sha}} | |
jobs: | |
unit-test: | |
environment: development | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
build-and-deploy: | |
needs: [unit-test] | |
environment: development | |
if: github.event_name == 'push' || github.event.pull_request.merged == true | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Bump version and push tag | |
id: tag | |
uses: anothrNick/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} | |
- name: 'Create env file' | |
run: | | |
echo "${{ secrets.ENV_FILE }}" > ./config/config.yml | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: linux/amd64 | |
push: true | |
tags: ${{vars.REPOSITORY}}:latest, ${{vars.REPOSITORY}}:${{ steps.tag.outputs.new_tag }} | |
- name: Deploy using ssh | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} # IP address or domain name in your ssh config | |
username: ${{ secrets.USERNAME }} # Username in your ssh config | |
key: ${{ secrets.SECRET_KEY }} # Run `cat ~/.ssh/id_rsa` and copy-paste here or run ssh-keygen -t rsa -b 4096 | |
port: 22 | |
# ../hieu/echo-template | |
script: | | |
if [ -d "${{ secrets.DIRECTORY }}" ]; then | |
echo "Directory exists, pulling from repo"; | |
cd "${{ secrets.DIRECTORY }}"; | |
git pull origin master; | |
else | |
echo "Directory does not exist, cloning repo"; | |
git clone "https://github.com/${{ github.repository }}" "${{ secrets.DIRECTORY }}"; | |
cd "${{ secrets.DIRECTORY }}"; | |
fi | |
echo "Installing dependencies"; | |
docker pull ${{vars.REPOSITORY}}:${{ steps.tag.outputs.new_tag }}; | |
docker rm -f template-echo; | |
docker run -d --name template-echo -p ${{secrets.EXPORT_PORT}}:${{secrets.CONTAINER_PORT}} ${{vars.REPOSITORY}}:${{ steps.tag.outputs.new_tag }}; |