Upgrade actions and push images to GitHub registry

pull/1/head
Stefano Ortolani 2023-12-06 14:15:19 +00:00
parent db79826104
commit 15534abba9
2 changed files with 38 additions and 26 deletions

View File

@ -1,34 +1,44 @@
name: Build the Docker images and push them to Docker Hub name: Build the Docker images and push them to Docker Hub
on: on:
# Only trigger the workflow when there is a new commit to the master branch
push: push:
branches: [ "master" ] branches: [ "master" ]
jobs: jobs:
deploy: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v3 uses: actions/checkout@v4
- name: Set up QEMU (for ARM emulation) - name: Set up QEMU
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v3
- name: Build the Docker images and push - name: Initialize environment
env: env:
GITHUB_CONTEXT: ${{ toJson(github) }} GITHUB_CONTEXT: ${{ toJson(github) }}
run: | run: |
# Initialize variables
DOCKER_IMG_TAG=`echo "${{ github.sha }}" | cut -c 1-7`
DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}
# Login
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
# Create the environment
sed -e '/^[[:space:]]*$/d' -e '/[#@]/d' -e 's/\"//g' -e 's/\(^[^=]*\)=\(.*\)/\1="\2"/' template.env > env.hcl sed -e '/^[[:space:]]*$/d' -e '/[#@]/d' -e 's/\"//g' -e 's/\(^[^=]*\)=\(.*\)/\1="\2"/' template.env > env.hcl
# Build and Push echo "DOCKER_IMG_TAG=`echo '${{ github.sha }}' | cut -c 1-7`" >> "$GITHUB_ENV"
DOCKER_IMG_TAG=$DOCKER_IMG_TAG DOCKER_USERNAME=$DOCKER_USERNAME docker buildx bake -f docker-bake.hcl -f env.hcl --push echo "DOCKER_USERNAME=MISP" >> "$GITHUB_ENV"
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/bake-action@v4
with:
push: true
files: docker-bake.hcl, env.hcl

View File

@ -1,7 +1,6 @@
name: Build the Docker images name: Build the Docker images
on: on:
# Only trigger the workflow when there is a PR on the master branch
pull_request: pull_request:
branches: [ "master" ] branches: [ "master" ]
@ -11,21 +10,24 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v3 uses: actions/checkout@v4
- name: Set up QEMU (for ARM emulation) - name: Set up QEMU
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v3
- name: Build the Docker images - name: Initialize environment
env: env:
GITHUB_CONTEXT: ${{ toJson(github) }} GITHUB_CONTEXT: ${{ toJson(github) }}
run: | run: |
# Initialize variables
DOCKER_IMG_TAG=`echo "${{ github.sha }}" | cut -c 1-7`
# Create the environment
sed -e '/^[[:space:]]*$/d' -e '/[#@]/d' -e 's/\"//g' -e 's/\(^[^=]*\)=\(.*\)/\1="\2"/' template.env > env.hcl sed -e '/^[[:space:]]*$/d' -e '/[#@]/d' -e 's/\"//g' -e 's/\(^[^=]*\)=\(.*\)/\1="\2"/' template.env > env.hcl
# Build and Push echo "DOCKER_IMG_TAG=`echo '${{ github.sha }}' | cut -c 1-7`" >> "$GITHUB_ENV"
DOCKER_IMG_TAG=$DOCKER_IMG_TAG DOCKER_USERNAME=local docker buildx bake -f docker-bake.hcl -f env.hcl echo "DOCKER_USERNAME=local" >> "$GITHUB_ENV"
- name: Build
uses: docker/bake-action@v4
with:
push: false
files: docker-bake.hcl, env.hcl