Docker build for arm64 #19
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: | |
workflow_dispatch: | |
push: | |
branches: | |
- master | |
tags: [ "*" ] | |
release: | |
types: [ published ] | |
env: | |
IMAGE: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]') | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build: | |
name: Build Docker Images | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
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: Log in to the Container registry | |
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: mutinywallet | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
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 |