Update build process #6
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: Release | |
on: | |
push: | |
branches: ["main"] | |
workflow_dispatch: | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Log in to GitHub Packages | |
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 | |
with: | |
username: ${{ secrets.GH_PACKAGES_USERNAME }} | |
password: ${{ secrets.GH_PACKAGES_PASSWORD }} | |
registry: ghcr.io | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Cache Docker layers | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Calculate version | |
run: | | |
YEAR=$(date +"%Y") | |
MONTH=$(date +"%m") | |
DAY=$(date +"%d") | |
NEW_TAG="v$YEAR.$MONTH.$DAY" | |
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV | |
echo "LATEST_TAG=ghcr.io/res-mon/dev-container:latest" >> $GITHUB_ENV | |
echo "PACKAGE_TAG=ghcr.io/res-mon/dev-container:$NEW_TAG" >> $GITHUB_ENV | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: "${{ env.LATEST_TAG }},\ | |
${{ env.PACKAGE_TAG }}" | |
builder: ${{ steps.buildx.outputs.name }} | |
platforms: linux/amd64,linux/arm64/v8 | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache |