From 03d153395245e14fd0e7589ebeea24722f9e128d Mon Sep 17 00:00:00 2001 From: broot5 <29516943+broot5@users.noreply.github.com> Date: Wed, 20 Mar 2024 20:23:54 +0900 Subject: [PATCH] Added action to upload image to ghcr --- .github/workflows/docker-image.yml | 18 ------------ .github/workflows/main.yml | 45 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 18 deletions(-) delete mode 100644 .github/workflows/docker-image.yml create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index 85812d3..0000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Docker Image CI - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Build the Docker image - run: docker build . --file Dockerfile --tag hbot:$(date +%s) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..9ece48a --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,45 @@ +name: Create and publish a Docker image + +on: push + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + latest=true + tags: | + type=sha + + - name: Build and push Docker image + id: build + uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file