Release Pipeline #2
Workflow file for this run
This file contains hidden or 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: Release Pipeline | |
on: | |
release: | |
types: | |
- published | |
jobs: | |
build-push-export-backend: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
# Checkout the repository | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
# Log in to GitHub Container Registry | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Build and push the Docker image | |
- name: Build and Push Docker Image | |
working-directory: ./backend | |
env: | |
VERSION: ${{ github.event.release.tag_name }} | |
run: | | |
# Build the Docker image | |
docker build -t ghcr.io/ikapiar/backend:${VERSION} . | |
# Push the Docker image | |
docker push ghcr.io/ikapiar/backend:${VERSION} | |
# Export the Docker image to an OCI-compatible tarball | |
- name: Export Docker Image | |
working-directory: ./backend | |
env: | |
VERSION: ${{ github.event.release.tag_name }} | |
run: | | |
# Save the Docker image as a tar file with the new naming format | |
docker save ghcr.io/ikapiar/backend:${VERSION} | gzip > ikapiar-backend_${VERSION}.tar.gz | |
# Upload the tarball to the release assets | |
- name: Upload Exported Image to Release | |
uses: actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ github.event.release.upload_url }} | |
asset_path: ./backend/ikapiar-backend_${VERSION}.tar.gz | |
asset_name: ikapiar-backend_${VERSION}.tar.gz | |
asset_content_type: application/gzip | |
build-and-deploy-frontend: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repository | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
# Set up Node.js environment | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 # Adjust based on your project requirements | |
# Install dependencies and build frontend | |
- name: Install and Build Frontend | |
working-directory: ./frontend | |
run: | | |
npm install | |
npm run build | |
# Deploy built static files using rsync | |
- name: Deploy Frontend to Server | |
env: | |
HOSTNAME: ${{ secrets.HOSTNAME }} | |
PORT: ${{ secrets.PORT }} | |
KEY: ${{ secrets.KEY }} | |
USERNAME: ${{ secrets.USERNAME }} | |
run: | | |
# Save SSH key to a temporary file | |
echo "$KEY" > /tmp/deploy_key | |
chmod 600 /tmp/deploy_key | |
# Use rsync to deploy static files | |
rsync -avz -e "ssh -p $PORT -i /tmp/deploy_key" ./frontend/out/ "$USERNAME@$HOSTNAME:/var/www/ikapiar" | |
# Clean up the temporary key | |
rm -f /tmp/deploy_key |