Ft schedule tech interview (#282) #165
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: Login to Digital Ocean and create a directory | |
on: | |
push: | |
branches: | |
- develop | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
env: | |
BACKEND_URL: ${{ secrets.BACKEND_URL }} | |
CLIENT_ID: ${{ secrets.CLIENT_ID }} | |
PUSHER_KEY: ${{ secrets.PUSHER_KEY }} | |
PUSHER_CLUSTER: ${{ secrets.PUSHER_CLUSTER }} | |
REACT_APP_CLOUDINARY_UPLOAD_PRESET: ${{ secrets.REACT_APP_CLOUDINARY_UPLOAD_PRESET }} | |
REACT_APP_CLOUDINARY_NAME: ${{ secrets.REACT_APP_CLOUDINARY_NAME }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
- name: Build and Push Docker Image | |
uses: docker/build-push-action@v4 | |
with: | |
push: true | |
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/atlp-devpulse-fn:latest | |
- name: Login to Digital Ocean Server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.DO_HOST }} | |
username: ${{ secrets.DO_USERNAME }} | |
key: ${{ secrets.DO_KEY }} | |
port: ${{ secrets.DO_PORT }} | |
envs: BACKEND_URL, PUSHER_KEY, PUSHER_CLUSTER, REACT_APP_CLOUDINARY_UPLOAD_PRESET, REACT_APP_CLOUDINARY_NAME, CLIENT_ID, JWT_SECRET | |
script: | | |
# Create .env file with required environment variables | |
cat <<EOF > .env | |
BACKEND_URL=${{ secrets.BACKEND_URL }} | |
CLIENT_ID=${{ secrets.CLIENT_ID }} | |
PUSHER_KEY=${{ secrets.PUSHER_KEY }} | |
PUSHER_CLUSTER=${{ secrets.PUSHER_CLUSTER }} | |
REACT_APP_CLOUDINARY_UPLOAD_PRESET=${{ secrets.REACT_APP_CLOUDINARY_UPLOAD_PRESET }} | |
REACT_APP_CLOUDINARY_NAME=${{ secrets.REACT_APP_CLOUDINARY_NAME }} | |
JWT_SECRET=${{ secrets.JWT_SECRET }} | |
EOF | |
# Pull the latest Docker image | |
docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/atlp-devpulse-fn:latest | |
# Stop and remove any existing container on port 4010 | |
existing_container=$(docker ps -q --filter "publish=4010") | |
if [ -n "$existing_container" ]; then | |
docker stop "$existing_container" | |
docker rm "$existing_container" | |
fi | |
# Run the new container | |
container_id=$(docker run -d \ | |
-p 4010:81 \ | |
--env-file .env \ | |
${{ secrets.DOCKER_HUB_USERNAME }}/atlp-devpulse-fn:latest) | |
echo "Container ID: $container_id" |