Skip to content

updated Dockerfile and cd.yml #5

updated Dockerfile and cd.yml

updated Dockerfile and cd.yml #5

Workflow file for this run

name: Deploy
on:
push:
branches:
- main
env:
IMAGE_NAME: ${{ github.event.repository.name }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
DB_USER_NAME: ${{ secrets.DB_USER_NAME }} # Add here environment variables first and then when reference it when you build the docker image
DB_USER_PASSWORD: ${{ secrets.DB_USER_PASSWORD }} # Add here environment variables first and then when reference it when you build the docker image
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: lower-repo
name: Repository to lowercase
run: |
echo "repository=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT
- name: Build & push docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
platforms: linux/amd64,linux/arm64 # Specify the platforms you need
tags: ghcr.io/${{ steps.lower-repo.outputs.repository }}:latest
build-args: |
DB_USER_NAME=${{ env.DB_USER_NAME }}
DB_USER_PASSWORD=${{ env.DB_USER_PASSWORD }}
#Add here your environment Variables which you implemented above
file: Dockerfile # Adjust if your Dockerfile is not in the root directory
outputs: digest
- name: Capture WildFly Logs
run: |
docker logs <container_id> | tee wildfly.log
cat wildfly.log
- name: Image digest
run: echo ${{ steps.build-and-push.outputs.digest }}
- uses: appleboy/[email protected]
name: Pull image and start container
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
script: |
docker container rm -f ${{ env.IMAGE_NAME }} 2> /dev/null || true
docker image rm ghcr.io/${{ steps.lower-repo.outputs.repository }}:latest 2> /dev/null || true
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
docker pull ghcr.io/${{ steps.lower-repo.outputs.repository }}:latest
docker run -d -p 8080:8080 --name ${{ env.IMAGE_NAME }} ghcr.io/${{ steps.lower-repo.outputs.repository }}:latest
# Explainaition for the last line:
# docker run -d -p [externalPort]:[internalPort] --name [imageName] ghcr.io/[repositoryOwner]/[repositoryName]:latest