Skip to content

Instantly share code, notes, and snippets.

@myst3k
Created July 3, 2024 00:51
Show Gist options
  • Save myst3k/0bf4bb3628555d3edc775d21b9334c42 to your computer and use it in GitHub Desktop.
Save myst3k/0bf4bb3628555d3edc775d21b9334c42 to your computer and use it in GitHub Desktop.
gh actions build and push to do
name: Build and to DO Apps
on:
workflow_dispatch:
push:
branches:
- 'release'
paths:
- '<my_workspace_name>/**'
env:
REGISTRY: registry.digitalocean.com
# IMAGE_NAME: ${{ github.repository }}
IMAGE_NAME: 'app/name'
jobs:
build-and-push-image:
runs-on: <self hosted runners name>
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Update/Install packages
run: |
sudo apt-get update && sudo apt-get -y install lld clang
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
password: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Setup Rust
uses: moonrepo/setup-rust@v1
with:
channel: '1.76.0'
cache-target: release
env:
RUSTFLAGS: -C linker=clang -C link-arg=-fuse-ld=lld
- run: cargo build --release --package <app_name> --bin <bin_name>
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./<workspace_name>/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment