Skip to content

Commit

Permalink
add aws-cli-php
Browse files Browse the repository at this point in the history
  • Loading branch information
tshinowpub committed Nov 11, 2021
1 parent 5a79079 commit 024c5e0
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 7 deletions.
18 changes: 11 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ jobs:
make ci:diff | while read DIR; do
cd ${CIRCLECI_WORKSPACE}/${DIR}
if find . -type f -name "Dockerfile${EXTENSION}" | grep Dockerfile ; then
make push;
if [[ "${DIR}" = "aws-cli-php" ]]; then
make push;
fi
else
echo "${DIR} is ${ARCH} not supported. make push was skipped.";
fi
Expand Down Expand Up @@ -172,7 +174,7 @@ jobs:
sudo mv ./hub-tool/hub-tool /usr/local/bin
expect -c "
set timeout 5
set timeout 10
spawn env hub-tool login ${DOCKER_REGISTRY_USERNAME}
expect \"Password:\"
send \"${DOCKER_REGISTRY_PASSWORD}\n\"
Expand All @@ -188,9 +190,11 @@ jobs:
make ci:diff
make ci:diff | while read DIR; do
if [[ -e "$CIRCLECI_WORKSPACE/$DIR/Dockerfile.arm64" ]] && [[ -e "$CIRCLECI_WORKSPACE/$DIR/Dockerfile" ]] ; then
cd ${CIRCLECI_WORKSPACE}/${DIR};
make build;
make manifest:push;
if [[ "${DIR}" = "aws-cli-php" ]]; then
cd ${CIRCLECI_WORKSPACE}/${DIR};
make build;
make manifest:push;
fi
fi
done
- run:
Expand Down Expand Up @@ -289,7 +293,7 @@ workflows:
- test
filters:
branches:
only: master
only: add_aws_cli_php
matrix:
parameters:
arch: [ x86_64, arm64 ]
Expand All @@ -300,7 +304,7 @@ workflows:
- push
filters:
branches:
only: master
only: add_aws_cli_php

update_dependecies:
jobs:
Expand Down
25 changes: 25 additions & 0 deletions aws-cli-php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ARG AWS_CLI_VERSION=2.3.5
ARG PHP_VERSION=8.0

FROM amazon/aws-cli:${AWS_CLI_VERSION}

ARG PHP_VERSION
ARG AWS_CLI_VERSION

LABEL version="${AWS_CLI_VERSION}-${PHP_VERSION}"
LABEL aws_cli_version="${AWS_CLI_VERSION}"
LABEL php_version="${PHP_VERSION}"
LABEL maintainer="[email protected]"

RUN amazon-linux-extras enable php${PHP_VERSION} \
&& yum install -y \
jq \
git \
php \
php-mbstring \
php-gmp \
php-mcrypt \
php-xml \
&& yum clean all

ENTRYPOINT ['/usr/local/bin/aws']
25 changes: 25 additions & 0 deletions aws-cli-php/Dockerfile.arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ARG AWS_CLI_VERSION=2.3.5
ARG PHP_VERSION=8.0

FROM amazon/aws-cli:${AWS_CLI_VERSION}

ARG PHP_VERSION
ARG AWS_CLI_VERSION

LABEL version="${AWS_CLI_VERSION}-${PHP_VERSION}"
LABEL aws_cli_version="${AWS_CLI_VERSION}"
LABEL php_version="${PHP_VERSION}"
LABEL maintainer="[email protected]"

RUN amazon-linux-extras enable php${PHP_VERSION} \
&& yum install -y \
jq \
git \
php \
php-mbstring \
php-gmp \
php-mcrypt \
php-xml \
&& yum clean all

ENTRYPOINT ['/usr/local/bin/aws']
87 changes: 87 additions & 0 deletions aws-cli-php/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
ARCH:=$(shell uname -m)
ENV:="dev"
LATEST_TAG:=$(shell if [ $(ENV) = "prod" ]; then \
echo "latest"; \
else \
echo "$(ENV)"; \
fi)
SCOPE_SUFFIX:=$(shell if [ $(ENV) = "prod" ]; then \
echo ""; \
else \
echo "-$(ENV)"; \
fi)
EXTENSION:=$(shell case "$(ARCH)" in \
("arm64"|"aarch64") echo ".arm64" ;; \
("x86_64") echo "" ;; \
(*) echo $(ARCH) ;; \
esac)

.PHONY: build
build:
@find . -type f -name "Dockerfile${EXTENSION}" | while read -r FILE; do \
docker build -f Dockerfile -t chatwork/`basename $$PWD` .; \
version=$$(docker inspect -f {{.Config.Labels.version}} chatwork/`basename $$PWD`:latest); \
aws_cli_version=$$(docker inspect -f {{.Config.Labels.aws_cli_version}} chatwork/`basename $$PWD`:latest); \
php_version=$$(docker inspect -f {{.Config.Labels.php_version}} chatwork/`basename $$PWD`:latest); \
if [ -n "$$version" ] && [ -n "$$aws_cli_version" ] && [ -n "$$php_version" ]; then \
docker tag chatwork/`basename $$PWD`:latest chatwork/`basename $$PWD`:$$version; \
fi \
done

.PHONY: check
check:
@version=$$(docker inspect -f {{.Config.Labels.version}} chatwork/`basename $$PWD`:latest); \
aws_cli_version=$$(docker inspect -f {{.Config.Labels.aws_cli_version}} chatwork/`basename $$PWD`:latest); \
php_version=$$(docker inspect -f {{.Config.Labels.php_version}} chatwork/`basename $$PWD`:latest); \
if [[ -z $$version ]]; then \
echo "\033[91mError: version is not defined in Dockerfile.\033[0m"; \
exit 1; \
fi; \
if [[ -z $$aws_cli_version ]]; then \
echo "\033[91mError: aws_cli_version is not defined in Dockerfile.\033[0m"; \
exit 1; \
fi; \
if [[ -z $$php_version ]]; then \
echo "\033[91mError: php_version is not defined in Dockerfile.\033[0m"; \
exit 1; \
fi; \
echo "\033[92mno problem.\033[0m";

.PHONY: test
test:
docker-compose -f docker-compose.test.yml up --build --no-start sut
docker cp $(shell pwd)/goss `basename $$PWD`:/goss
docker-compose -f docker-compose.test.yml up --no-recreate --exit-code-from sut sut

.PHONY: push
push:
@version=$$(docker inspect -f {{.Config.Labels.version}} chatwork/`basename $$PWD`:latest); \
if docker inspect --format='{{index .RepoDigests 0}}' chatwork/$$(basename $$PWD):$$version >/dev/null 2>&1; then \
echo "no changes"; \
else \
docker tag chatwork/`basename $$PWD`:latest chatwork/`basename $$PWD`:$$version-$(ARCH)$(SCOPE_SUFFIX); \
docker push chatwork/`basename $$PWD`:$$version-$(ARCH)$(SCOPE_SUFFIX); \
fi

.PHONY: manifest\:push
manifest\:push:
@version=$$(docker inspect -f {{.Config.Labels.version}} chatwork/`basename $$PWD`:latest); \
if docker inspect --format='{{index .RepoDigests 0}}' chatwork/$$(basename $$PWD):$$version >/dev/null 2>&1; then \
echo "no changes"; \
else \
docker pull chatwork/`basename $$PWD`:$$version-aarch64$(SCOPE_SUFFIX); \
docker pull chatwork/`basename $$PWD`:$$version-x86_64$(SCOPE_SUFFIX); \
arm64_digest=$$(docker inspect -f '{{index .RepoDigests 0}}' chatwork/`basename $$PWD`:$$version-aarch64$(SCOPE_SUFFIX)); \
amd64_digest=$$(docker inspect -f '{{index .RepoDigests 0}}' chatwork/`basename $$PWD`:$$version-x86_64$(SCOPE_SUFFIX)); \
docker buildx imagetools create -t chatwork/`basename $$PWD`:$$version$(SCOPE_SUFFIX) $$arm64_digest $$amd64_digest; \
docker buildx imagetools create -t chatwork/`basename $$PWD`:$(LATEST_TAG) $$arm64_digest $$amd64_digest; \
hub-tool tag rm chatwork/`basename $$PWD`:$$version-aarch64$(SCOPE_SUFFIX) -f; \
hub-tool tag rm chatwork/`basename $$PWD`:$$version-x86_64$(SCOPE_SUFFIX) -f; \
fi

.PHONY: manifest\:succeed-message
manifest\:succeed-message:
@version=$$(docker inspect -f {{.Config.Labels.version}} chatwork/aws-cli-php:latest); \
echo "Released new tags."; \
echo "- chatwork/aws-cli-php:$$version$(SCOPE_SUFFIX)"; \
echo "- chatwork/aws-cli-php:$(LATEST_TAG)";
9 changes: 9 additions & 0 deletions aws-cli-php/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# aws-cli-php

aws-cli-php is an image of [aws-cli](https://hub.docker.com/r/amazon/aws-cli) with php

## Usage

```
$ docker run -it chatwork/aws-cli-php help
```
20 changes: 20 additions & 0 deletions aws-cli-php/docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3'
services:
aws-cli-php:
build:
context: .
image: chatwork/aws-cli-php
entrypoint: /bin/bash
sut:
image: chatwork/dgoss:latest
environment:
GOSS_FILES_PATH: /goss
GOSS_FILES_STRATEGY: cp
entrypoint: ""
command: /usr/local/bin/dgoss run --entrypoint "" chatwork/aws-cli-php tail -f /dev/null
container_name: aws-cli-php
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./goss/goss.yaml:/goss/goss.yaml
depends_on:
- aws-cli-php
8 changes: 8 additions & 0 deletions aws-cli-php/goss/goss.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
command:
php -v:
exit-status: 0
stdout:
- "/^PHP 8.[0-9]+/"

aws help:
exit-status: 0
Empty file added aws-cli-php/hooks/test
Empty file.
4 changes: 4 additions & 0 deletions aws-cli-php/variant.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies:
awscli:
version: 2.3.5
previousVersion: 2.3.4
18 changes: 18 additions & 0 deletions aws-cli-php/variant.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
provisioners:
textReplace:
Dockerfile:
from: "ARG AWS_CLI_VERSION={{ .awscli.previousVersion }}"
to: "ARG AWS_CLI_VERSION={{ .awscli.version }}"
Dockerfile.arm64:
from: "ARG AWS_CLI_VERSION={{ .awscli.previousVersion }}"
to: "ARG AWS_CLI_VERSION={{ .awscli.version }}"
goss/goss.yaml:
from: "- {{ .awscli.previousVersion }}"
to: "- {{ .awscli.version }}"

dependencies:
aws-cli:
releasesFrom:
dockerImageTags:
source: amazon/aws-cli
version: "> 2.3.5"

0 comments on commit 024c5e0

Please sign in to comment.