diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index 56f327c7..aa13deca 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -1,4 +1,3 @@ - name: Create and publish a Docker image on: @@ -10,42 +9,50 @@ on: pull_request: env: - IMAGE_NAME: ${{ github.repository }} -# -jobs: + IMAGE_NAME: ghcr.io/adorsys/didcomm-mediator-rs +jobs: push: runs-on: ubuntu-latest permissions: packages: write contents: read - # + steps: - - uses: actions/checkout@v4 + - name: Check out repository + uses: actions/checkout@v4 + - name: Install Docker Compose run: | sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose - - name: Build image - run: docker-compose build --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" - - - name: Log in to registry + - name: Log in to GitHub Container Registry run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - # - - name: Push image + + - name: Build Docker image run: | - IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME + echo "Checking for .env file..." + if [ -f .env ]; then + echo ".env file exists." + else + echo ".env file does not exist." + exit 1 + fi - # This changes all uppercase characters to lowercase. - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - # This strips the git ref prefix from the version. VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') - # This strips the "v" prefix from the tag name. + [[ "${{ github.ref }}" == "refs/heads/main" ]] && VERSION=latest [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') - # This uses the Docker `latest` tag convention. - [ "$VERSION" == "main" ] && VERSION=latest - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $IMAGE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION + + echo "Building image with version: $VERSION" + docker-compose build + docker tag ${IMAGE_NAME}:latest ${IMAGE_NAME}:${VERSION} + + - name: Push Docker image + run: | + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + [[ "${{ github.ref }}" == "refs/heads/main" ]] && VERSION=latest + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + + echo "Pushing image ${IMAGE_NAME}:${VERSION}" + docker push ${IMAGE_NAME}:${VERSION} \ No newline at end of file