MO-850 update docker compose version #87
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: CI-CD-pipeline | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
name: Build, Push and Deploy | |
permissions: | |
contents: read | |
packages: write | |
env: | |
REGISTRY: ghcr.io | |
REPOSITORY: ${{ github.repository }} | |
SHORT_SHA: ${GITHUB_SHA:0:8} | |
steps: | |
- name: Set image tag to environment variables | |
run: | | |
echo "IMAGE_TAG=${{ env.SHORT_SHA }}" >> $GITHUB_ENV | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
push: true | |
tags: "${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}" | |
- name: Set environment variables to env-file | |
run: | | |
echo "REGISTRY=${{ env.REGISTRY }}" > .env | |
echo "REPOSITORY=${{ env.REPOSITORY }}" >> .env | |
echo "TAG=${{ env.IMAGE_TAG }}" >> .env | |
- name: copy docker-compose and environment variables to server | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.REMOTE_SERVER_HOSTNAME }} | |
username: ${{ secrets.REMOTE_SERVER_USERNAME }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
port: ${{ secrets.REMOTE_SSH_PORT }} | |
source: "docker-compose.yml,.env" | |
target: "/opt/docker/btp-landing" | |
- name: Deploy to remote server | |
env: | |
SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "$SSH_KEY" > ~/.ssh/id_ed25519 | |
chmod 600 ~/.ssh/id_ed25519 | |
ssh -o StrictHostKeyChecking=no -i "~/.ssh/id_ed25519" ${{ secrets.REMOTE_SERVER_USERNAME }}@${{ secrets.REMOTE_SERVER_HOSTNAME }} -p ${{ secrets.REMOTE_SSH_PORT }} ' | |
cd /opt/docker/btp-landing | |
docker login ${{ env.REGISTRY }} -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} | |
docker pull ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }} | |
docker compose up -d | |
docker image prune --filter="label=metaimagename=steven-signal-landing" -a -f | |
' |