Update readme to proper repos #17
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: CICD | |
on: | |
push: | |
branches: | |
- master | |
env: | |
IMAGE: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]') | |
jobs: | |
build: | |
name: Build Docker Images | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout master | |
uses: actions/checkout@v1 | |
- name: Set environment variables | |
run: | | |
echo "IMAGE=$(echo ${{env.IMAGE}} )" >> $GITHUB_ENV | |
- name: Log in to GitHub Packages | |
run: echo ${PERSONAL_ACCESS_TOKEN} | docker login ghcr.io -u ${{ secrets.NAMESPACE }} --password-stdin | |
env: | |
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
- name: Pull images | |
run: | | |
docker pull ${{ env.IMAGE }} || true | |
- name: Build images | |
run: | | |
DOCKER_BUILDKIT=1 docker build -f Dockerfile -t ${{ env.IMAGE }}:latest . | |
- name: Push images | |
run: | | |
docker push ${{ env.IMAGE }}:latest | |
deploy: | |
name: Deploy to Linode | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout master | |
uses: actions/checkout@v1 | |
- name: Add environment variables to .env | |
run: | | |
echo "IMAGE=${{ env.IMAGE }}" >> .env | |
echo "LINODE_USER=${{ secrets.LINODE_USER }}" >> .env | |
echo "NAMESPACE=${{ secrets.NAMESPACE }}" >> .env | |
echo "PERSONAL_ACCESS_TOKEN=${{ secrets.PERSONAL_ACCESS_TOKEN }}" >> .env | |
- name: Add the private SSH key to the ssh-agent | |
env: | |
SSH_AUTH_SOCK: /tmp/ssh_agent.sock | |
run: | | |
mkdir -p ~/.ssh | |
ssh-agent -a $SSH_AUTH_SOCK > /dev/null | |
ssh-keyscan github.com >> ~/.ssh/known_hosts | |
ssh-add - <<< "${{ secrets.PRIVATE_KEY }}" | |
- name: Build and deploy images on Linode | |
env: | |
SSH_AUTH_SOCK: /tmp/ssh_agent.sock | |
run: | | |
scp -o StrictHostKeyChecking=no -r ./.env ${{ secrets.LINODE_USER }}@${{ secrets.LINODE_IP_ADDRESS }}:/home/${{ secrets.LINODE_USER }}/app | |
ssh -o StrictHostKeyChecking=no ${{ secrets.LINODE_USER }}@${{ secrets.LINODE_IP_ADDRESS }} "\ | |
export LINODE_USER=$LINODE_USER; \ | |
export IMAGE=$IMAGE; \ | |
export NAMESPACE=$NAMESPACE; \ | |
export PERSONAL_ACCESS_TOKEN=$PERSONAL_ACCESS_TOKEN; \ | |
bash -s" << 'ENDSSH' | |
cd /home/proxyuser/app | |
source .env | |
docker login ghcr.io -u $NAMESPACE -p $PERSONAL_ACCESS_TOKEN | |
docker pull $IMAGE | |
docker stop ln-websocket-proxy | |
docker rm ln-websocket-proxy | |
docker run --restart unless-stopped -d --name ln-websocket-proxy -p 8080:8080 $IMAGE | |
ENDSSH |